<?php
/**
 *
 * ClassName: Htmlsearchparser_model
 *
 * description...
 *
 * @author wanghaifei <wanghaifei@soften.cn>
 *
 */
class Htmlsearchparser_model extends CI_Model {
	
	/**
	 * html页面抓取数据
	 *
	 * @var array
	 */
	private $result = array ();
	
	/**
	 * html页面抓取的转发数据
	 *
	 * @var array
	 */
	private $tweet = array ();
	
	/**
	 * html页面抓取的转发内容
	 *
	 * @var string
	 */
	private $deltext = '';
	
	/**
	 * html页面抓取新浪微博时使用的标签
	 * 
	 * @var string
	 */
	private $crawl_use_tab = '';
	
	/**
	 * 抓取微博信息后存储在mongodb的字段
	 *
	 * @var array
	 */
	var $wbfield = array (
			'_id' => '', // 微博ID
			               // 'idstr' =>'',//字符串型的微博ID
			'text' => '', // 微博信息内容
			'ctime' => '', // 微博创建时间
			'source' => '', // 微博来源
			'reposts_count' => '', // 转发数
			'comments_count' => '', // 评论数
			'attitudes_count' => '', // 表态数(好评数)
			'retweeted_id' => '', // 转载的微博ID
			'retweeted_uid' => '', // 转载的微博用户ID
			'retweeted_name' => '', // 转载的微博用户名
			'url' => '', // 详情URL
			'thumbnail_pic' => '', // 缩略图片地址，没有时不返回此字段
			'bmiddle_pic' => '', // 中等尺寸图片地址，没有时不返回此字段
			'original_pic' => '', // 原始图片地址，没有时不返回此字段
			'addtime' => '', // 增加时间
			'source_myid' => '', // 渠道ID抓取渠道
			'user' => Array (
					'id' => '', // 用户ID
					'profile_url' => '', // 用户空间URL
					'name' => '', // 昵称
					'description' => '', // 描述
					'header_url' => '', // 头像
					'followers_count' => '', // 粉丝数
					'friends_count' => '', // 关注数
					'verified' => '' 
			) // 是否加V
 
	);
	
	/**
	 * xxxxxxx
	 *
	 * @access public
	 * @param string $charset
	 *        	xxxxx [Must]
	 * @param array $contentType
	 *        	xxxxxx [Optional]
	 * @param int $display
	 *        	xxxxxxxxx [Optional]
	 * @param bool $display
	 *        	xxxxxxxxx [Optional]
	 * @return string $mixed
	 */
	public function __construct() {
		parent::__construct ();
		$this->load->helper ( 'MY_common_helper' );
		$this->load->helper ( 'MY_http_helper' );
	}
	
	/**
	 * 清除结果信息
	 *
	 * @access public
	 * @return string $mixed
	 */
	public function clear() {
		$this->tweet = array ();
		$this->result = array ();
		$this->crawl_use_tab = '';
	}
	
	/**
	 * 解析新浪平台HTML搜索结果页面内容，提出标准微博内容数组
	 *
	 * @access public
	 * @param array $platform_info
	 *        	新浪微博搜索平台配置信息 [Must]
	 * @param string $html
	 *        	新浪微博搜索结果HTML代码 [Must]
	 * @return array 微博结果数组
	 */
	public function parser_sina_html($platform_info, $html) {
		if (empty ( $platform_info ) || ! is_array ( $platform_info ) || empty ( $html )) {
			log_message ( 'error', "parser_sina param is error !! platform_info:{$platform_info} --- html_content:{$html}", FALSE, 'keyword/sina' );
			return false;
		}
		
		// $start_str = '<dl class=\\\"feed_list W_linecolor\\\"';
		$start_str = '<div class=\\\"WB_cardwrap S_bg2 clearfix\\\" >';
		$end_str = '<div node-type=\\\"feed_list_repeat\\\"';
		
		if (preg_match_all ( '|' . $start_str . '(.*?)' . $end_str . '|ims', $html, $matches )) {
			$feed_list = $matches [1];
			
			foreach ( $feed_list as $k => $userinfo ) {
				$current_data = $this->wbfield;
				
				$userinfo = str_replace ( array (
						'\\"',
						'\\/' 
				), array (
						'"',
						'/' 
				), $userinfo );
				
				$tweet = $this->forward_sina_html ( $platform_info, $userinfo );
				if ($tweet != FALSE) {
					$current_data ['retweeted_id'] = $tweet ['retweeted_id'];
					$current_data ['retweeted_uid'] = $tweet ['retweeted_uid'];
					$current_data ['retweeted_name'] = $tweet ['retweeted_name'];
				}
				
				$retweet_pattern = '|<div class=\"comment\">.*?<\/div>\s*<\/div>\s*<\/div>\s*<\/div>|ims';
				$userinfo = preg_replace ( $retweet_pattern, '', $userinfo );
				
				if ($this->deltext) {
					$userinfo = str_replace ( $this->deltext, '', $userinfo );
					$this->deltext = '';
				}
				;
				//echo $userinfo;exit;
				if (preg_match ( '|<a class=\"W_texta W_fb\" nick-name=\"(.*?)\" href=\"(.*?)\" target=\"_blank\" title=\"(.*?)\".*?class=\"name_txt W_fb\">|ims', $userinfo, $matches )) {
					// 昵称
					$current_data ['user'] ['name'] = iconv_decode ( $matches [1] );
					
					// 用户URL
					$current_data ['user'] ['profile_url'] = $matches [2];
					
					// 用户描述
					//$current_data ['user'] ['description'] = iconv_decode ( $matches [3] );
					
					// 用户ID
					//$current_data ['user'] ['id'] = $matches [4];
					
					
				}
				
				// 头像
				preg_match ( '|<img src=\"(.*?)\".*?alt=\"(.*?)\"|ims', $userinfo, $matches );
				$current_data ['user'] ['header_url'] = $matches [1];
				
				// 是否加V
				if (preg_match ( '|<a.*?class=\"W_icon icon_approve.*?|ims', $userinfo, $Vmatches )) {
					$use_verified = 1;
				} else {
					$use_verified = 0;
				}
				$current_data ['user'] ['verified'] = $use_verified;
				
				// 内容
				preg_match ( '|<p class=\"comment_txt\" node-type=\"feed_list_content\".*?>(.*?)<\/p>|ims', $userinfo, $Cmatches );
				
				$current_data ['text'] = iconv_decode ( $Cmatches [1] );
				$current_data ['text'] = trim ( strip_tags ( $current_data ['text'], "<a><img>" ) );
				$arr = array (
						"\n",
						"\\n",
						"\t",
						"\\t",
						"\r",
						"\\r" 
				);
				$current_data ['text'] = str_replace ( $arr, array (
						'',
						'',
						'' 
				), $current_data ['text'] );
				
				// 图片
				preg_match ( '|<li class=\"WB_pic S_bg2 bigcursor\">.*?<img.*?src=\"(.*?)\".*?<\/li>|ims', $userinfo, $Imatches );
				if ($Imatches) {
					$current_data ['thumbnail_pic'] = $Imatches [1];
					$current_data ['bmiddle_pic'] = str_replace ( 'square', 'bmiddle', $Imatches [1] );
					;
					$current_data ['original_pic'] = str_replace ( 'square', 'large', $Imatches [1] );
					;
				}
				
				if (preg_match ( '|allowForward.*?&url=(.*?)&mid=(.*?)&name=(.*?)&uid=.*?\\\u8f6c\\\u53d1<em>(.*?)<\/em>?|ims', $userinfo, $RTmatches )) {
					// 详情URL
					$current_data ['url'] = $RTmatches [1];
					// 详情ID
					$current_data ['_id'] = $RTmatches [2];
					// 转发
					$current_data ['reposts_count'] = isset ( $RTmatches [4] ) ? $RTmatches [4] : 0;
					
					//2016年12月13日 更新从链接中取用户ID
					$urlarr = explode('/',$RTmatches [1]);
					$current_data ['user'] ['id'] = $urlarr[3];
				}
				
				if (preg_match ( '|\\\u8bc4\\\u8bba<em>(.*?)<\/em>|ims', $userinfo, $COMMmatches )) {
					$current_data ['comments_count'] = $COMMmatches [1];
				}
				
				// 表态数(好评数)
				if (preg_match ( '|<i class=\"W_ico12 icon_praised_b\"><\/i><em>(.*?)<\/em>|ims', $userinfo, $matches )) { // var_dump($matches);
					$current_data ['attitudes_count'] = $matches [1];
				}
				
				// 来源
				if (preg_match ( '|title=\"[^"]*\" date=\"(.*?)\".*?rel="nofollow">(.*?)<\/a>|', $userinfo, $matches )) {
					$current_data ['ctime'] = substr ( $matches [1], 0, 10 );
					$current_data ['source'] = iconv_decode ( $matches [2] );
				}
				
				// 增加时间
				$current_data ['addtime'] = time ();
				// 渠道
				$current_data ['source_myid'] = $platform_info ['source_myid'];
				
				$this->result [$current_data ['_id']] = $current_data;
			}
		} else {
			log_message ( 'error', "Data of parser_sina is null from Htmlsearchparser_model,matches is error!!", FALSE, 'keyword/sina' );
			return false;
		}
		
		if (count ( $this->tweet ) > 0) {
			foreach ( $this->tweet as $key => $value ) {
				$this->result [$key] = $value;
			}
		}
		return $this->result;
	}
	public function parser_sina_phone($platform_info, $html) {
		if (empty ( $platform_info ) || ! is_array ( $platform_info ) || empty ( $html )) {
			log_message ( 'error', "parser_sina param is error !! platform_info:{$platform_info} --- html_content:{$html}", FALSE, 'keyword/sina' );
			return false;
		}
	
		$result = json_decode ( $html, true );
		
		$result = $result['data'];
	
		if (! empty ( $result ) && isset ( $result ['cards'] )) {
			$cards = $result ['cards'];
				
			foreach ($cards as $val){
				foreach ( $val['card_group'] as $k => $card ) {
					$card_group = $card;
	
					if (empty ( $card_group ) || (! isset ( $card_group ['mblog'] ))) {
						continue;
					}
						
					$mblog = $card_group ['mblog'];
	
					$current_data = $this->wbfield;
	
					$current_data ['_id'] = strval ( $mblog ['id'] );
	
					// 内容
					$current_data ['text'] = strip_tags($mblog ['text']);
	
					// 时间
					$current_data ['ctime'] = my_strtotime($mblog ['created_at']);
	
					// 来源
					$current_data ['source'] = $mblog ['source'];
	
					// 转评赞
					$current_data ['reposts_count'] = intval($mblog ['reposts_count']);
					$current_data ['comments_count'] = intval($mblog ['comments_count']);
					$current_data ['attitudes_count'] = intval($mblog ['attitudes_count']);
	
					// 转发
					if (isset ( $mblog ['retweeted_status'] )) {
	
						$retweeted_status = $mblog ['retweeted_status'];
	
						$current_data ['retweeted_id'] = strval ( $retweeted_status ['id'] );
						$current_data ['retweeted_uid'] = strval ( $retweeted_status ['user'] ['id'] );
						$current_data ['retweeted_name'] = strval ( $retweeted_status ['user'] ['screen_name'] );
	
						$retweeted = $this->wbfield;
	
						$retweeted ['_id'] = strval ( $retweeted_status ['id'] );
	
						// 内容
						$retweeted ['text'] = strip_tags($retweeted_status ['text']);
	
						// 时间
						$retweeted ['ctime'] = my_strtotime($retweeted_status ['created_at']);
	
						// 来源
						$retweeted ['source'] = $retweeted_status ['source'];
	
						// 转评赞
						$retweeted ['reposts_count'] = intval($retweeted_status ['reposts_count']);
						$retweeted ['comments_count'] = intval($retweeted_status ['comments_count']);
						$retweeted ['attitudes_count'] = intval($retweeted_status ['attitudes_count']);
	
						// 连接
						$retweeted ['url'] = "http://weibo.com/{$retweeted_status['user']['id']}/{$retweeted_status['bid']}";
	
						// 图片
						$retweeted ['thumbnail_pic'] = $retweeted_status ['thumbnail_pic'];
						$retweeted ['bmiddle_pic'] = $retweeted_status ['bmiddle_pic'];
						$retweeted ['original_pic'] = $retweeted_status ['original_pic'];
						
						if($retweeted_status ['pics']){
							$pics = $retweeted_status ['pics'];
								
							foreach ($pics as $pic){
								$retweeted ['pics'] [] = $pic['url'];
							}
						}
						
						// 昵称
						$retweeted ['user'] ['id'] = strval ( $retweeted_status ['user'] ['id'] );
						$retweeted ['user'] ['profile_url'] = "{$retweeted_status['user']['profile_url']}";
						$retweeted ['user'] ['name'] = $retweeted_status ['user'] ['screen_name'];
						$retweeted ['user'] ['description'] = $retweeted_status ['user'] ['description'];
						$retweeted ['user'] ['header_url'] = $retweeted_status ['user'] ['profile_image_url'];
						$retweeted ['user'] ['followers_count'] =str_replace('万','0000',$retweeted_status ['user'] ['followers_count']);
						$retweeted ['user'] ['friends_count'] = $retweeted_status ['user'] ['follow_count'];
						$retweeted ['user'] ['statuses_count'] = $retweeted_status ['user'] ['statuses_count'];
						$retweeted ['user'] ['verified'] = $retweeted_status ['user'] ['verified'] == "true" ? 1 : 0;
						$retweeted ['user'] ['gender'] = $retweeted_status ['user'] ['gender'];
	
						// 增加时间
						$retweeted ['addtime'] = time ();
						// 渠道
						$retweeted ['source_myid'] = $platform_info ['source_myid'];
	
						$this->result [] = $retweeted;
					}
	
					// 连接
					$current_data ['url'] = "http://weibo.com/{$mblog['user']['id']}/{$mblog['bid']}";
	
					// 图片
					$current_data ['thumbnail_pic'] = $mblog ['thumbnail_pic'];
					$current_data ['bmiddle_pic'] = $mblog ['bmiddle_pic'];
					$current_data ['original_pic'] = $mblog ['original_pic'];
					
					if($mblog ['pics']){
						$pics = $mblog ['pics'];
							
						foreach ($pics as $pic){
							$current_data ['pics'] [] = $pic['url'];
						}
					}
					
					// 昵称
					$current_data ['user'] ['id'] = strval ( $mblog ['user'] ['id'] );
					$current_data ['user'] ['profile_url'] = $mblog['user']['profile_url'];
					$current_data ['user'] ['name'] = $mblog ['user'] ['screen_name'];
					$current_data ['user'] ['description'] = $mblog ['user'] ['description'];
					$current_data ['user'] ['header_url'] = $mblog ['user'] ['profile_image_url'];
					$current_data ['user'] ['followers_count'] = $mblog ['user'] ['followers_count'];
					$current_data ['user'] ['friends_count'] = $mblog ['user'] ['follow_count'];
					$current_data ['user'] ['statuses_count'] = $mblog ['user'] ['statuses_count'];
					$current_data ['user'] ['verified'] = $mblog ['user'] ['verified'] == true ? 1 : 0;
					$current_data ['user'] ['gender'] = $mblog ['user'] ['gender'];
	
					// 增加时间
					$current_data ['addtime'] = time ();
					// 渠道
					$current_data ['source_myid'] = $platform_info ['source_myid'];
	
					$this->result [] = $current_data;
				}
			}
				
		} else {
			log_message ( 'error', "Data of parser_sina is null from Htmlsearchparser_model,matches is error!!", FALSE, 'keyword/sina' );
			return false;
		}
	
		return $this->result;
	}
/* 	public function parser_sina_phone($platform_info, $html) {
		if (empty ( $platform_info ) || ! is_array ( $platform_info ) || empty ( $html )) {
			log_message ( 'error', "parser_sina param is error !! platform_info:{$platform_info} --- html_content:{$html}", FALSE, 'keyword/sina' );
			return false;
		}
	
		$result = json_decode ( $html, true );
	
		if (! empty ( $result ) && isset ( $result ['cards'] )) {
			$cards = $result ['cards'];
				
			foreach ( $cards as $k => $card ) {
				$card_group = $card;
	
				if (empty ( $card_group ) || (! isset ( $card_group ['mblog'] ))) {
					continue;
				}
				$mblog = $card_group ['mblog'];
	
				$current_data = $this->wbfield;
	
				$current_data ['_id'] = strval ( $mblog ['id'] );
	
				// 内容
				$current_data ['text'] = strip_tags($mblog ['text']);
	
				// 时间
				$current_data ['ctime'] = my_strtotime($mblog ['created_at']);
	
				// 来源
				$current_data ['source'] = $mblog ['source'];
	
				// 转评赞
				$current_data ['reposts_count'] = intval($mblog ['reposts_count']);
				$current_data ['comments_count'] = intval($mblog ['comments_count']);
				$current_data ['attitudes_count'] = intval($mblog ['attitudes_count']);
	
				// 转发
				if (isset ( $mblog ['retweeted_status'] )) {
						
					$retweeted_status = $mblog ['retweeted_status'];
						
					$current_data ['retweeted_id'] = strval ( $retweeted_status ['id'] );
					$current_data ['retweeted_uid'] = strval ( $retweeted_status ['user'] ['id'] );
					$current_data ['retweeted_name'] = strval ( $retweeted_status ['user'] ['screen_name'] );
						
					$retweeted = $this->wbfield;
						
					$retweeted ['_id'] = strval ( $retweeted_status ['id'] );
						
					// 内容
					$retweeted ['text'] = strip_tags($retweeted_status ['text']);
						
					// 时间
					$retweeted ['ctime'] = my_strtotime($retweeted_status ['created_at']);
						
					// 来源
					$retweeted ['source'] = $retweeted_status ['source'];
						
					// 转评赞
					$retweeted ['reposts_count'] = intval($retweeted_status ['reposts_count']);
					$retweeted ['comments_count'] = intval($retweeted_status ['comments_count']);
					$retweeted ['attitudes_count'] = intval($retweeted_status ['attitudes_count']);
						
					// 连接
					$retweeted ['url'] = "http://weibo.com/{$retweeted_status['user']['id']}/{$retweeted_status['bid']}";
						
					// 图片
					$retweeted ['thumbnail_pic'] = $retweeted_status ['thumbnail_pic'];
					$retweeted ['bmiddle_pic'] = $retweeted_status ['bmiddle_pic'];
					$retweeted ['original_pic'] = $retweeted_status ['original_pic'];
						
					// 昵称
					$retweeted ['user'] ['id'] = strval ( $retweeted_status ['user'] ['id'] );
					$retweeted ['user'] ['profile_url'] = "{$retweeted_status['user']['profile_url']}";
					$retweeted ['user'] ['name'] = $retweeted_status ['user'] ['screen_name'];
					$retweeted ['user'] ['description'] = $retweeted_status ['user'] ['description'];
					$retweeted ['user'] ['header_url'] = $retweeted_status ['user'] ['profile_image_url'];
					$retweeted ['user'] ['followers_count'] =str_replace('万','0000',$retweeted_status ['user'] ['followers_count']);
					$retweeted ['user'] ['friends_count'] = $retweeted_status ['user'] ['follow_count'];
					$retweeted ['user'] ['verified'] = $retweeted_status ['user'] ['verified'] == "true" ? 1 : 0;
						
					// 增加时间
					$retweeted ['addtime'] = time ();
					// 渠道
					$retweeted ['source_myid'] = $platform_info ['source_myid'];
						
					$this->result [] = $retweeted;
				}
	
				// 连接
				$current_data ['url'] = "http://weibo.com/{$mblog['user']['id']}/{$mblog['mblogid']}";
	
				// 图片
				$current_data ['thumbnail_pic'] = $mblog ['thumbnail_pic'];
				$current_data ['bmiddle_pic'] = $mblog ['bmiddle_pic'];
				$current_data ['original_pic'] = $mblog ['original_pic'];
	
				// 昵称
				$current_data ['user'] ['id'] = strval ( $mblog ['user'] ['id'] );
				$current_data ['user'] ['profile_url'] = "http://weibo.com{$mblog['user']['profile_url']}";
				$current_data ['user'] ['name'] = $mblog ['user'] ['screen_name'];
				$current_data ['user'] ['description'] = $mblog ['user'] ['description'];
				$current_data ['user'] ['header_url'] = $mblog ['user'] ['profile_image_url'];
				$current_data ['user'] ['followers_count'] = $mblog ['user'] ['followers_count'];
				$current_data['user']['friends_count'] = $mblog ['user'] ['follow_count'];
				$current_data ['user'] ['verified'] = $mblog ['user'] ['verified'] == true ? 1 : 0;
	
				// 增加时间
				$current_data ['addtime'] = time ();
				// 渠道
				$current_data ['source_myid'] = $platform_info ['source_myid'];
	
				$this->result [] = $current_data;
			}
		} else {
			log_message ( 'error', "Data of parser_sina is null from Htmlsearchparser_model,matches is error!!", FALSE, 'keyword/sina' );
			return false;
		}
	
		return $this->result;
	} */

	//根据博主抓取返回的数据  2016年12月22日
	public function parser_sina_phone_user($platform_info, $html) {
		if (empty ( $platform_info ) || ! is_array ( $platform_info ) || empty ( $html )) {
			log_message ( 'error', "parser_sina param is error !! platform_info:{$platform_info} --- html_content:{$html}", FALSE, 'keyword/sina' );
			return false;
		}
	
		$result = json_decode ( $html, true );
	
		if (! empty ( $result ) && isset ( $result ['cards'] )) {
			$cards = $result ['cards'];
	
			foreach ( $cards as $k => $card ) {
				$card_group = $card;
	
				if (empty ( $card_group ) || (! isset ( $card_group ['mblog'] ))) {
					continue;
				}
				$mblog = $card_group ['mblog'];
	
				$current_data = $this->wbfield;
	
				$current_data ['_id'] = strval ( $mblog ['id'] );
	
				// 内容
				$current_data ['text'] = strip_tags($mblog ['text']);
	
				// 时间
				$current_data ['ctime'] = my_strtotime($mblog ['created_at']);
	
				// 来源
				$current_data ['source'] = $mblog ['source'];
	
				// 转评赞
				$current_data ['reposts_count'] = intval($mblog ['reposts_count']);
				$current_data ['comments_count'] = intval($mblog ['comments_count']);
				$current_data ['attitudes_count'] = intval($mblog ['attitudes_count']);
	
				// 转发
				if (isset ( $mblog ['retweeted_status'] )) {
	
					$retweeted_status = $mblog ['retweeted_status'];
	
					$current_data ['retweeted_id'] = strval ( $retweeted_status ['id'] );
					$current_data ['retweeted_uid'] = strval ( $retweeted_status ['user'] ['id'] );
					$current_data ['retweeted_name'] = strval ( $retweeted_status ['user'] ['screen_name'] );
	
					$retweeted = $this->wbfield;
	
					$retweeted ['_id'] = strval ( $retweeted_status ['id'] );
	
					// 内容
					$retweeted ['text'] = strip_tags($retweeted_status ['text']);
	
					// 时间
					$retweeted ['ctime'] = my_strtotime($retweeted_status ['created_at']);
	
					// 来源
					$retweeted ['source'] = $retweeted_status ['source'];
	
					// 转评赞
					$retweeted ['reposts_count'] = intval($retweeted_status ['reposts_count']);
					$retweeted ['comments_count'] = intval($retweeted_status ['comments_count']);
					$retweeted ['attitudes_count'] = intval($retweeted_status ['attitudes_count']);
	
					// 连接
					$retweeted ['url'] = "http://weibo.com/{$retweeted_status['user']['id']}/{$retweeted_status['bid']}";
	
					// 图片
					$retweeted ['thumbnail_pic'] = $retweeted_status ['thumbnail_pic'];
					$retweeted ['bmiddle_pic'] = $retweeted_status ['bmiddle_pic'];
					$retweeted ['original_pic'] = $retweeted_status ['original_pic'];
	
					// 昵称
					$retweeted ['user'] ['id'] = strval ( $retweeted_status ['user'] ['id'] );
					$retweeted ['user'] ['profile_url'] = "{$retweeted_status['user']['profile_url']}";
					$retweeted ['user'] ['name'] = $retweeted_status ['user'] ['screen_name'];
					$retweeted ['user'] ['description'] = $retweeted_status ['user'] ['description'];
					$retweeted ['user'] ['header_url'] = $retweeted_status ['user'] ['profile_image_url'];
					$retweeted ['user'] ['followers_count'] =str_replace('万','0000',$retweeted_status ['user'] ['followers_count']);
					$retweeted ['user'] ['friends_count'] = $retweeted_status ['user'] ['follow_count'];
					$retweeted ['user'] ['statuses_count'] = $retweeted_status ['user'] ['statuses_count'];
					$retweeted ['user'] ['verified'] = $retweeted_status ['user'] ['verified'] == "true" ? 1 : 0;
					$retweeted ['user'] ['gender'] = $retweeted_status ['user'] ['gender'];
	
					// 增加时间
					$retweeted ['addtime'] = time ();
					// 渠道
					$retweeted ['source_myid'] = $platform_info ['source_myid'];
	
					$this->result [] = $retweeted;
				}
	
				// 连接
				$current_data ['url'] = "http://weibo.com/{$mblog['user']['id']}/{$mblog['bid']}";
	
				// 图片
				$current_data ['thumbnail_pic'] = $mblog ['thumbnail_pic'];
				$current_data ['bmiddle_pic'] = $mblog ['bmiddle_pic'];
				$current_data ['original_pic'] = $mblog ['original_pic'];
				//博文图片附件
				if(!empty($mblog['pics'])){
					foreach ($mblog['pics'] as $val){
						$current_data['pics'][]=$val['url'];
					}
				}
				
	
				// 昵称
				$current_data ['user'] ['id'] = strval ( $mblog ['user'] ['id'] );
				$current_data ['user'] ['profile_url'] = "http://weibo.com{$mblog['user']['profile_url']}";
				$current_data ['user'] ['name'] = $mblog ['user'] ['screen_name'];
				$current_data ['user'] ['description'] = $mblog ['user'] ['description'];
				$current_data ['user'] ['header_url'] = $mblog ['user'] ['profile_image_url'];
				$current_data ['user'] ['followers_count'] = $mblog ['user'] ['followers_count'];
				$current_data ['user'] ['friends_count'] = $mblog ['user'] ['follow_count'];
				$current_data ['user'] ['statuses_count'] = $mblog ['user'] ['statuses_count'];
				$current_data ['user'] ['verified'] = $mblog ['user'] ['verified'] == true ? 1 : 0;
				$current_data ['user'] ['gender'] = $mblog ['user'] ['gender'];
	
				// 增加时间
				$current_data ['addtime'] = time ();
				// 渠道
				$current_data ['source_myid'] = $platform_info ['source_myid'];
	
				$this->result [] = $current_data;
			}
		} else {
			log_message ( 'error', "Data of parser_sina is null from Htmlsearchparser_model,matches is error!!", FALSE, 'keyword/sina' );
			return false;
		}
	
		return $this->result;
	}

	//根据博主抓取返回的数据  2016年12月22日
	public function parser_sina_phone_info( $html) {
		if ( empty ( $html )) {
			log_message ( 'error', "parser_sina param is error !! html_content:{$html}", FALSE, 'keyword/sina' );
			return false;
		}
	
		preg_match_all('|var \$render_data \= \[(.*?)\]\[0\]|ims', $html, $out, PREG_PATTERN_ORDER);
		

		$data = array();
		
		if($out[1][0]){
			$info = json_decode($out[1][0], TRUE);
			
			$data['rpsCnt'] = $info['status']['reposts_count'];
			$data['cmtCnt'] = $info['status']['comments_count'];
			$data['atdCnt'] = $info['status']['attitudes_count'];
		}else{
			log_message ( 'error', "Data of parser_sina is null from Htmlsearchparser_model,matches is error!!", FALSE, 'keyword/sina' );
			return false;
		}
		
		$this->result = $data;
		
		/*if (! empty ($html) && isset ($html)) {
			$ru = '|<script>(.*?)</script>|ims';
			preg_match_all($ru,$html,$c,PREG_PATTERN_ORDER);
			$su = '|"pics":.*?"reposts_count":(.*?),|ims';
			preg_match_all($su,$c[0][0],$d,PREG_PATTERN_ORDER);
			$data['reposts_count'] = $d[1][0];
			$hu = '|"pics":.*?"comments_count":(.*?),|ims';
			preg_match_all($hu,$c[0][0],$f,PREG_PATTERN_ORDER);
			$data['comments_count'] = $f[1][0];
			$uu = '|"pics":.*?"attitudes_count":(.*?),|ims';
			preg_match_all($uu,$c[0][0],$e,PREG_PATTERN_ORDER);
			$data['attitudes_count'] = $e[1][0];
			$this->result = $data;
		} else {
			log_message ( 'error', "Data of parser_sina is null from Htmlsearchparser_model,matches is error!!", FALSE, 'keyword/sina' );
			return false;
		}*/
	
		return $this->result;
	}
	
	/**
	 * 通过接口，抓取新浪博主详情信息
	 * @param unknown $html
	 * @return boolean|multitype:
	 */
	public function parser_sina_user_phone_info( $html) {
		if ( empty ( $html )) {
			log_message ( 'error', "parser_sina_user_phone_info param is error !! html_content:{$html}", FALSE, 'keyword/sina' );
			return false;
		}
	
		$data = array();
		$info = json_decode($html, TRUE);
	
		$cards = $info['cards'];
	
		foreach ($cards as $card){
				
			$card_group = $card['card_group'];
				
			foreach ((array)$card_group as $group){
				if($group['item_name'] == "所在地"){
					$data['province'] = $group['item_content'];
				}
			}
		}
	
		$this->result = $data;
	
		return $this->result;
	}
	
	
	/**
	 * 新浪手机端抓取
	 *
	 * @param unknown $platform_info        	
	 * @param unknown $html        	
	 * @return boolean|multitype:
	 */
	public function parser_sina_phone_old($platform_info, $html) {
		if (empty ( $platform_info ) || ! is_array ( $platform_info ) || empty ( $html )) {
			log_message ( 'error', "parser_sina param is error !! platform_info:{$platform_info} --- html_content:{$html}", FALSE, 'keyword/sina' );
			return false;
		}
		
		$result = json_decode ( $html, true );
		
		if (! empty ( $result ) && isset ( $result ['cards'] )) {
			$cards = $result ['cards'];
			
			foreach ( $cards as $k => $card ) {
				$card_group = $card ['card_group'] [0];
				
				if (empty ( $card_group ) || (! isset ( $card_group ['mblog'] ))) {
					continue;
				}
				$mblog = $card_group ['mblog'];
				
				$current_data = $this->wbfield;
				
				$current_data ['_id'] = strval ( $mblog ['id'] );
				
				// 内容
				$current_data ['text'] = strip_tags($mblog ['text']);
				
				// 时间
				$current_data ['ctime'] = $mblog ['created_timestamp'];
				
				// 来源
				$current_data ['source'] = $mblog ['source'];
				
				// 转评赞
				$current_data ['reposts_count'] = $mblog ['reposts_count'];
				$current_data ['comments_count'] = $mblog ['comments_count'];
				$current_data ['attitudes_count'] = $mblog ['attitudes_count'];
				
				// 转发
				if (isset ( $mblog ['retweeted_status'] )) {
					
					$retweeted_status = $mblog ['retweeted_status'];
					
					$current_data ['retweeted_id'] = strval ( $retweeted_status ['id'] );
					$current_data ['retweeted_uid'] = strval ( $retweeted_status ['user'] ['id'] );
					$current_data ['retweeted_name'] = strval ( $retweeted_status ['user'] ['screen_name'] );
					
					$retweeted = $this->wbfield;
					
					$retweeted ['_id'] = strval ( $retweeted_status ['id'] );
					
					// 内容
					$retweeted ['text'] = strip_tags($retweeted_status ['text']);
					
					// 时间
					$retweeted ['ctime'] = $retweeted_status ['created_timestamp'];
					
					// 来源
					$retweeted ['source'] = $retweeted_status ['source'];
					
					// 转评赞
					$retweeted ['reposts_count'] = $retweeted_status ['reposts_count'];
					$retweeted ['comments_count'] = $retweeted_status ['comments_count'];
					$retweeted ['attitudes_count'] = $retweeted_status ['attitudes_count'];
					
					// 连接
					$retweeted ['url'] = "http://weibo.com/{$retweeted_status['user']['id']}/{$retweeted_status['bid']}";
					
					// 图片
					$retweeted ['thumbnail_pic'] = $retweeted_status ['thumbnail_pic'];
					$retweeted ['bmiddle_pic'] = $retweeted_status ['bmiddle_pic'];
					$retweeted ['original_pic'] = $retweeted_status ['original_pic'];
					
					// 昵称
					$retweeted ['user'] ['id'] = strval ( $retweeted_status ['user'] ['id'] );
					$retweeted ['user'] ['profile_url'] = "http://weibo.com{$retweeted_status['user']['profile_url']}";
					$retweeted ['user'] ['name'] = $retweeted_status ['user'] ['screen_name'];
					$retweeted ['user'] ['description'] = $retweeted_status ['user'] ['description'];
					$retweeted ['user'] ['header_url'] = $retweeted_status ['user'] ['profile_image_url'];
					$retweeted ['user'] ['followers_count'] =str_replace('万','0000',$retweeted_status ['user'] ['fansNum']) ;
					// $retweeted['user']['friends_count'] = "";
					$retweeted ['user'] ['verified'] = $retweeted_status ['user'] ['verified'] ? $mblog ['user'] ['verified'] : 0;
					
					// 增加时间
					$retweeted ['addtime'] = time ();
					// 渠道
					$retweeted ['source_myid'] = $platform_info ['source_myid'];
					
					$this->result [] = $retweeted;
				}
				
				// 连接
				$current_data ['url'] = "http://weibo.com/{$mblog['user']['id']}/{$mblog['mblogid']}";
				
				// 图片
				$current_data ['thumbnail_pic'] = $mblog ['thumbnail_pic'];
				$current_data ['bmiddle_pic'] = $mblog ['bmiddle_pic'];
				$current_data ['original_pic'] = $mblog ['original_pic'];
				
				// 昵称
				$current_data ['user'] ['id'] = strval ( $mblog ['user'] ['id'] );
				$current_data ['user'] ['profile_url'] = "http://weibo.com{$mblog['user']['profile_url']}";
				$current_data ['user'] ['name'] = $mblog ['user'] ['screen_name'];
				$current_data ['user'] ['description'] = $mblog ['user'] ['description'];
				$current_data ['user'] ['header_url'] = $mblog ['user'] ['profile_image_url'];
				$current_data ['user'] ['followers_count'] = $mblog ['user'] ['fansNum'];
				// $current_data['user']['friends_count'] = "";
				$current_data ['user'] ['verified'] = $mblog ['user'] ['verified'] ? $mblog ['user'] ['verified'] : 0;
				
				// 增加时间
				$current_data ['addtime'] = time ();
				// 渠道
				$current_data ['source_myid'] = $platform_info ['source_myid'];
				
				$this->result [] = $current_data;
			}
		} else {
			log_message ( 'error', "Data of parser_sina is null from Htmlsearchparser_model,matches is error!!", FALSE, 'keyword/sina' );
			return false;
		}
		
		return $this->result;
	}
	
	public function parser_sina_phone_kehuduan($platform_info, $html) {
		if (empty ( $platform_info ) || ! is_array ( $platform_info ) || empty ( $html )) {
			log_message ( 'error', "parser_sina param is error !! platform_info:{$platform_info} --- html_content:{$html}", FALSE, 'keyword/sina' );
			return false;
		}
	
		$result = json_decode ( $html, true );
	
		if (! empty ( $result ) && isset ( $result ['cards'] )) {
			$cards = $result ['cards'];
				
			foreach ( $cards as $k => $card ) {
				$card_group = $card;
	
				if (empty ( $card_group ) || (! isset ( $card_group ['mblog'] ))) {
					continue;
				}
				$mblog = $card_group ['mblog'];
				
				$current_data = $this->wbfield;
	
				$current_data ['_id'] = strval ( $mblog ['id'] );
	
				// 内容
				$current_data ['text'] = strip_tags($mblog ['text']);
	
				// 时间
				$current_data ['ctime'] = strtotime($mblog ['created_at']);
	
				// 来源
				$current_data ['source'] = $mblog ['source'];
	
				// 转评赞
				$current_data ['reposts_count'] = intval($mblog ['reposts_count']);
				$current_data ['comments_count'] = intval($mblog ['comments_count']);
				$current_data ['attitudes_count'] = intval($mblog ['attitudes_count']);
	
				// 转发
				if (isset ( $mblog ['retweeted_status'] )) {
						
					$retweeted_status = $mblog ['retweeted_status'];
						
					$current_data ['retweeted_id'] = strval ( $retweeted_status ['id'] );
					$current_data ['retweeted_uid'] = strval ( $retweeted_status ['user'] ['id'] );
					$current_data ['retweeted_name'] = strval ( $retweeted_status ['user'] ['screen_name'] );
						
					$retweeted = $this->wbfield;
						
					$retweeted ['_id'] = strval ( $retweeted_status ['id'] );
						
					// 内容
					$retweeted ['text'] = strip_tags($retweeted_status ['text']);
						
					// 时间
					$retweeted ['ctime'] = $retweeted_status ['created_timestamp'];
						
					// 来源
					$retweeted ['source'] = $retweeted_status ['source'];
						
					// 转评赞
					$retweeted ['reposts_count'] = $retweeted_status ['reposts_count'];
					$retweeted ['comments_count'] = $retweeted_status ['comments_count'];
					$retweeted ['attitudes_count'] = $retweeted_status ['attitudes_count'];
						
					// 连接
					$retweeted ['url'] = "http://weibo.com/{$retweeted_status['user']['id']}/{$retweeted_status['bid']}";
						
					// 图片
					$retweeted ['thumbnail_pic'] = $retweeted_status ['thumbnail_pic'];
					$retweeted ['bmiddle_pic'] = $retweeted_status ['bmiddle_pic'];
					$retweeted ['original_pic'] = $retweeted_status ['original_pic'];
						
					// 昵称
					$retweeted ['user'] ['id'] = strval ( $retweeted_status ['user'] ['id'] );
					$retweeted ['user'] ['profile_url'] = "http://weibo.com{$retweeted_status['user']['profile_url']}";
					$retweeted ['user'] ['name'] = $retweeted_status ['user'] ['screen_name'];
					$retweeted ['user'] ['description'] = $retweeted_status ['user'] ['description'];
					$retweeted ['user'] ['header_url'] = $retweeted_status ['user'] ['profile_image_url'];
					$retweeted ['user'] ['followers_count'] =str_replace('万','0000',$retweeted_status ['user'] ['followers_count']) ;
					$retweeted ['user'] ['friends_count'] = $retweeted_status ['user'] ['friends_count'];
					$retweeted ['user'] ['verified'] = $retweeted_status ['user'] ['verified'] ? $mblog ['user'] ['verified'] : 0;
						
					// 增加时间
					$retweeted ['addtime'] = time ();
					// 渠道
					$retweeted ['source_myid'] = $platform_info ['source_myid'];
						
					$this->result [] = $retweeted;
				}
	
				// 连接
				$current_data ['url'] = "http://weibo.com/{$mblog['user']['id']}/{$mblog['mblogid']}";
	
				// 图片
				$current_data ['thumbnail_pic'] = $mblog ['thumbnail_pic'];
				$current_data ['bmiddle_pic'] = $mblog ['bmiddle_pic'];
				$current_data ['original_pic'] = $mblog ['original_pic'];
	
				// 昵称
				$current_data ['user'] ['id'] = strval ( $mblog ['user'] ['id'] );
				$current_data ['user'] ['profile_url'] = "http://weibo.com{$mblog['user']['profile_url']}";
				$current_data ['user'] ['name'] = $mblog ['user'] ['screen_name'];
				$current_data ['user'] ['description'] = $mblog ['user'] ['description'];
				$current_data ['user'] ['header_url'] = $mblog ['user'] ['profile_image_url'];
				$current_data ['user'] ['followers_count'] = $mblog ['user'] ['followers_count'];
				$current_data ['user'] ['friends_count'] = $mblog ['user'] ['friends_count'];
				$current_data ['user'] ['verified'] = $mblog ['user'] ['verified'] ? $mblog ['user'] ['verified'] : 0;
	
				// 增加时间
				$current_data ['addtime'] = time ();
				// 渠道
				$current_data ['source_myid'] = $platform_info ['source_myid'];
	
				$this->result [] = $current_data;
			}
		} else {
			log_message ( 'error', "Data of parser_sina is null from Htmlsearchparser_model,matches is error!!", FALSE, 'keyword/sina' );
			return false;
		}
	
		return $this->result;
	}
	
	/**
	 * 解析新浪平台HTML搜索结果页面内容，提出标准微博内容数组
	 *
	 * @access public
	 * @param array $platform_info
	 *        	新浪微博搜索平台配置信息 [Must]
	 * @param string $html
	 *        	新浪微博搜索结果HTML代码 [Must]
	 * @return array 微博结果数组
	 */
	public function parser_sina_html_old($platform_info, $html) {
		if (empty ( $platform_info ) || ! is_array ( $platform_info ) || empty ( $html )) {
			log_message ( 'error', "parser_sina param is error !! platform_info:{$platform_info} --- html_content:{$html}", FALSE, 'keyword/sina' );
			return false;
		}
		
		$start_str = '<dl class=\\\"feed_list\\\"';
		$end_str = '<dd class=\\\"clear\\\"><\\\/dd>';
		
		if (preg_match_all ( '|' . $start_str . '(.*?)' . $end_str . '|ims', $html, $matches )) {
			$feed_list = $matches [1];
			
			foreach ( $feed_list as $k => $userinfo ) {
				$current_data = $this->wbfield;
				
				$userinfo = str_replace ( array (
						'\\"',
						'\\/' 
				), array (
						'"',
						'/' 
				), $userinfo );
				
				$tweet = $this->forward_sina_html ( $platform_info, $userinfo );
				if ($tweet != FALSE) {
					$current_data ['retweeted_id'] = $tweet ['retweeted_id'];
					$current_data ['retweeted_uid'] = $tweet ['retweeted_uid'];
					$current_data ['retweeted_name'] = $tweet ['retweeted_name'];
				}
				
				if ($this->deltext) {
					$userinfo = str_replace ( $this->deltext, '', $userinfo );
					$this->deltext = '';
				}
				;
				
				if (preg_match ( '|<a href="(.*?)".*?title="(.*?)".*?suda-data=".*?weibo_nologin_name:(.*?)"|ims', $userinfo, $matches )) {
					// 用户URL
					$current_data ['user'] ['profile_url'] = $matches [1];
					// 昵称
					$current_data ['user'] ['name'] = iconv_decode ( $matches [2] );
					// 用户ID
					$current_data ['user'] ['id'] = $matches [3];
				}
				
				// 头像
				preg_match ( '|<img src="(.*?)".*?alt="(.*?)"|ims', $userinfo, $matches );
				$current_data ['user'] ['header_url'] = $matches [1];
				
				// 是否加V
				if (preg_match ( '|<img.*?class="approve.*?|ims', $userinfo, $Vmatches )) {
					$use_verified = 1;
				} else {
					$use_verified = 0;
				}
				$current_data ['user'] ['verified'] = $use_verified;
				
				// 内容
				preg_match ( '|<em>(.*?)</em>|ims', $userinfo, $Cmatches );
				
				$current_data ['text'] = iconv_decode ( $Cmatches [1] );
				
				// 图片
				preg_match ( '|<img class="bigcursor.*?src="(.*?)"|ims', $userinfo, $Imatches );
				if ($Imatches) {
					$current_data ['thumbnail_pic'] = $Imatches [1];
					$current_data ['bmiddle_pic'] = str_replace ( 'thumbnail', 'bmiddle', $Imatches [1] );
					;
					$current_data ['original_pic'] = str_replace ( 'thumbnail', 'large', $Imatches [1] );
					;
				}
				
				if (preg_match ( '|allowForward.*?&url=(.*?)&mid=(.*?)&name=(.*?)&uid=.*?\\\u8f6c\\\u53d1(\((.*?)\))?|ims', $userinfo, $RTmatches )) {
					// 详情URL
					$current_data ['url'] = $RTmatches [1];
					// 详情ID
					$current_data ['_id'] = $RTmatches [2];
					// 转发
					$current_data ['reposts_count'] = isset ( $RTmatches [5] ) ? $RTmatches [5] : 0;
				}
				
				if (preg_match ( '|\\\u8bc4\\\u8bba(\((.*?)\))?.*?date="(.*?)"|ims', $userinfo, $COMMmatches )) {
					// 评论
					$current_data ['comments_count'] = $COMMmatches [2] ? $COMMmatches [2] : 0;
					
					// 时间
					$time = substr ( $COMMmatches [3], 0, 10 );
					$current_data ['ctime'] = $time;
				}
				
				// 表态数(好评数)
				if (preg_match ( '|\\\u8d5e</em>\((.*?)\)</a>|ims', $userinfo, $matches )) { // var_dump($matches);
					$current_data ['attitudes_count'] = $matches [1];
				}
				
				// 来源
				if (preg_match ( '|<a.*? rel="nofollow">(.*?)</a>|ims', $userinfo, $SCmatches )) {
					$current_data ['source'] = iconv_decode ( $SCmatches [1] );
				}
				
				// 增加时间
				$current_data ['addtime'] = time ();
				// 渠道
				$current_data ['source_myid'] = $platform_info ['source_myid'];
				
				$this->result [$current_data ['_id']] = $current_data;
			}
		} else {
			log_message ( 'error', "Data of parser_sina is null from Htmlsearchparser_model,matches is error!!", FALSE, 'keyword/sina' );
			return false;
		}
		
		if (count ( $this->tweet ) > 0) {
			foreach ( $this->tweet as $key => $value ) {
				$this->result [$key] = $value;
			}
		}
		return $this->result;
	}
	
	/**
	 * 解析新浪平台WAP版搜索结果页面内容，提出标准微博内容数组
	 *
	 * @access public
	 * @param array $platform_info
	 *        	新浪微博搜索平台配置信息 [Must]
	 * @param string $html
	 *        	新浪微博搜索结果HTML代码 [Must]
	 * @return array 微博结果数组
	 */
	public function parser_sina($platform_info, $html) {
		if (empty ( $platform_info ) || ! is_array ( $platform_info ) || empty ( $html )) {
			log_message ( 'error', "parser_sina param is error !! platform_info:{$platform_info} --- html_content:{$html}", FALSE, 'keyword/sina' );
			return false;
		}
		
		$start_str = '<div class="c" id=';
		$end_str = '<div class="s">';
		if (preg_match_all ( '|' . $start_str . '"M_(.*?)">(.*?)' . $end_str . '|ims', $html, $matches )) {
			$feed_list = $matches [2];
			foreach ( $feed_list as $k => $userinfo ) {
				$this->deltext = '';
				$current_data = $this->wbfield;
				
				// 是否转载
				if (false != ($retweeted = $this->forward_sina ( $platform_info, $userinfo ))) {
					
					$current_data ['retweeted_id'] = $retweeted ['id'];
					$current_data ['retweeted_uid'] = $retweeted ['uid'];
					$current_data ['retweeted_name'] = $retweeted ['name'];
				}
				
				// 如果有转发
				if ($this->deltext) {
					$userinfo = str_replace ( $this->deltext, '', $userinfo );
					$this->deltext = '';
				}
				
				// 微博URL, 微博ID ( 1266321801/ymbsPjH6I )
				if (preg_match ( '|<a href="http://weibo.cn/comment/(.*?)\?uid=(\d*).*?"|ims', $userinfo, $matches )) {
					$current_data ['user'] ['id'] = $matches [2];
					$current_data ['mid'] = $matches [1];
					$current_data ['_id'] = $this->sinaWburl2ID ( $matches [1] );
					$current_data ['url'] = 'http://weibo.cn/' . $matches [2] . '/' . $matches [1];
				}
				
				if (preg_match ( '|<a class="nk" href="(.*?)">(.*?)</a>(.*)<a href=".*?">赞|ims', $userinfo, $matches )) {
					$current_data ['user'] ['profile_url'] = $matches [1];
					$current_data ['user'] ['name'] = $matches [2];
					
					$current_data ['text'] = trim ( strip_tags ( $matches [3], '<a>' ) );
				}
				$current_data ['text'] = preg_replace ( '|<a href.*?</a>|ims', '', $current_data ['text'] );
				// 去掉首字符":"
				$headstr = substr ( $current_data ['text'], 0, 1 );
				if ($headstr == ':') {
					$current_data ['text'] = substr ( $current_data ['text'], 1 );
				}
				
				// 图片
				if (preg_match ( '|.*<img src="(.*?)".*alt="图片"|is', $userinfo, $matches )) {
					$current_data ['thumbnail_pic'] = $matches [1];
					$current_data ['bmiddle_pic'] = str_replace ( 'wap128', 'bmiddle', $matches [1] );
					$current_data ['original_pic'] = str_replace ( 'wap128', 'woriginal', $matches [1] );
				}
				
				// 是否加V
				if (preg_match ( '|<img src=".*?" alt="V">|ims', $userinfo, $Vmatches )) {
					$use_verified = 1;
				} else {
					$use_verified = 0;
				}
				$current_data ['user'] ['verified'] = $use_verified;
				
				// 渠道
				$current_data ['source_myid'] = $platform_info ['source_myid'];
				
				// 转发
				if (preg_match ( '|转发\[(.*?)\]|ims', $userinfo, $matches )) {
					$current_data ['reposts_count'] = $matches [1];
				}
				// 评论
				if (preg_match ( '|评论\[(.*?)\]|ims', $userinfo, $matches )) {
					$current_data ['comments_count'] = $matches [1];
				}
				
				// 表态数(好评数)
				if (preg_match ( '|赞\[(.*?)\]|ims', $userinfo, $matches )) {
					$current_data ['attitudes_count'] = $matches [1];
				}
				
				// 创建时间
				if (preg_match ( '|<span class="ct">(.*?)</span>|ims', $userinfo, $matches )) {
					list ( $ctime, $source ) = explode ( '&nbsp;', $matches [1] );
					$ctime = my_strtotime ( $ctime );
					$current_data ['ctime'] = $ctime;
					$current_data ['source'] = strip_tags ( str_replace ( '来自', '', $source ) );
				}
				// 增加时间
				$current_data ['addtime'] = time ();
				// 渠道
				$current_data ['source_myid'] = $platform_info ['source_myid'];
				$this->result [] = $current_data;
			}
		} else {
			log_message ( 'error', "Data of parser_sina is null from Htmlsearchparser_model,matches is error!!", FALSE, 'keyword/sina' );
			return false;
		}
		
		return $this->result; // 因wap版转发的信息没有发布时间..所以此处暂时不要转发的信息
			                      // return array_merge($this->result, $this->tweet);
	}
	
	/**
	 * 解析云云平台HTML搜索结果页面内容，提出标准微博内容数组
	 *
	 * @access public
	 * @param array $platform_info
	 *        	云云微博搜索平台配置信息 [Must]
	 * @param string $html
	 *        	云云微博搜索结果HTML代码 [Must]
	 * @return array 微博结果数组
	 */
	
	// 解析wap页面，由于抓取web页面IP被封,暂时解析wap页面
	public function parser_yunyun($platform_info, $html) {
		if (empty ( $platform_info ) || ! is_array ( $platform_info ) || empty ( $html )) {
			log_message ( 'error', "parser_yun param is error !! platform_info:{$platform_info} --- html_content:{$html}", FALSE, 'keyword/yunyun' );
			return false;
		}
		
		// 所有的时间 ;
		if (preg_match_all ( '|renderTimeMap[(](.*?)[)];|ims', $html, $matches )) {
			$eval_data = json_decode ( $matches [1] [0], TRUE );
		} else {
			return false;
		}
		
		$start_str = '<div class="search" id="search_contentcontainer">';
		$end_str = '<form id="search_form_footer"';
		$start_str = preg_quote ( $start_str, '/' );
		$end_str = preg_quote ( $end_str, '/' );
		
		preg_match ( '/' . $start_str . '(.*?)' . $end_str . '/ims', $html, $matches );
		$feed_list = $matches [1];
		
		if (preg_match_all ( '|class="s_shi">(.*?)</dl>|ims', $feed_list, $matches )) {
			$infolist = $matches [1];
			
			foreach ( $infolist as $info ) {
				$current_data = $this->wbfield;
				
				// 发布时间
				if (preg_match ( '|<span id="ts_(\d+)" class="time".*?</span>|ims', $info, $matches )) {
					$time = 'ts_' . $matches [1];
					$current_data ['ctime'] = isset ( $eval_data ) ? $eval_data [$time] : time ();
				}
				// 用户头像
				if (preg_match ( '|<div class="m_user_pic">.*?<img src="(.*?)".*?</div>|ims', $info, $matches )) {
					$current_data ['user'] ['header_url'] = $matches [1];
				}
				// 昵称
				if (preg_match ( '|<dd class="shi_tit">(.*?)</dd>|ims', $info, $matches )) {
					if (preg_match_all ( '|<a href="http://weibom\.yunyun\.com/SClick\.php\?rd=(.*?)&.*?">(.*?)</a>|ims', $matches [1], $matches )) {
						$url = urldecode ( $matches [1] [0] );
						$user_url = urldecode ( $matches [1] [1] );
						
						// 文章ID, 详情URL, 用户ID, 用户URL
						
						if (strpos ( $url, 'weibo.com' ) || strpos ( $url, 'weibo.cn' )) {
							$current_data ['url'] = $url;
							
							$url = explode ( '/', $url );
							$count = count ( $url );
							$current_data ['mid'] = $url [$count - 1];
							$current_data ['_id'] = $this->sinaWburl2ID ( $url [$count - 1] );
							$current_data ['user'] ['id'] = $url [$count - 2];
							$current_data ['user'] ['profile_url'] = $user_url;
							
							$platform = 'sina';
						} elseif (strpos ( $url, 'qq.com' )) {
							$url = explode ( '=', $url );
							$user_url = explode ( '=', $user_url );
							
							$current_data ['_id'] = $url [1];
							$current_data ['url'] = 'http://t.qq.com/t/p/' . $url [1];
							
							$current_data ['user'] ['id'] = $user_url [1];
							$current_data ['user'] ['profile_url'] = 'http://t.qq.com/' . $user_url [1];
							
							$platform = 'tencent';
						} elseif (strpos ( $url, 'sohu.com' )) {
							$current_data ['user'] ['profile_url'] = $user_url;
							$current_data ['url'] = $url;
							
							$url = explode ( '/', $url );
							$user_url = explode ( '/', $user_url );
							
							$count = count ( $url );
							$user_url_count = count ( $user_url );
							
							$current_data ['_id'] = $url [$count - 1];
							$current_data ['user'] ['id'] = $url [$user_url_count - 1];
							
							$platform = 'sohu';
						} elseif (strpos ( $url, '163.com' )) {
							$current_data ['url'] = $url;
							
							$url = explode ( '/', $url );
							$count = count ( $url );
							$current_data ['_id'] = $url [$count - 1];
							$current_data ['user'] ['id'] = $url [$count - 3];
							$current_data ['user'] ['profile_url'] = $user_url;
							
							$platform = 'netease';
						}
						// 平台
						$current_data ['platform'] = $platform;
						// 昵称
						$current_data ['user'] ['name'] = $matches [2] [1];
					}
				}
				// 内容
				if (preg_match ( '|<p>(.*?)</p>|ims', $info, $matches )) {
					$current_data ['text'] = $matches [1];
				}
				$thumbnail_pic = '';
				// 微博内容中的图片
				if (preg_match ( '|<img id="cc\.\d*\.ivili" src="(.*?)">|ims', $info, $matches )) {
					$current_data ['thumbnail_pic'] = $thumbnail_pic = $matches [1];
				}
				if ($platform == 'sina') {
					$current_data ['bmiddle_pic'] = str_replace ( 'thumbnail', 'bmiddle', $thumbnail_pic );
					$current_data ['original_pic'] = str_replace ( 'thumbnail', 'woriginal', $thumbnail_pic );
				} elseif ($platform == 'tencent') {
					$current_data ['bmiddle_pic'] = str_replace ( '120', '460', $thumbnail_pic );
					$current_data ['original_pic'] = str_replace ( '120', '2000', $thumbnail_pic );
				} elseif ($platform == 'netease') {
					$current_data ['bmiddle_pic'] = str_replace ( 'w=120', 'w=240', $thumbnail_pic );
					$current_data ['original_pic'] = str_replace ( 'w=120', 'w=440', $thumbnail_pic );
				} elseif ($platform == 'sohu') {
					// 无法获取大图和原图
				}
				
				// 评论
				if (preg_match ( '|评论 (\d+)|ims', $info, $matches )) {
					$current_data ['comments_count'] = $matches [1];
				}
				// 转发
				if (preg_match ( '|转发 (\d+)|ims', $info, $matches )) {
					$current_data ['reposts_count'] = $matches [1];
				}
				// 增加时间
				$current_data ['addtime'] = time ();
				// 渠道
				$current_data ['source_myid'] = $platform_info ['source_myid'];
				
				$this->result [] = $current_data;
			}
		} else {
			return false;
		}
		
		return $this->result;
	}
	
	/**
	 * 解析云云平台HTML搜索结果页面内容，提出标准微博内容数组
	 *
	 * @access public
	 * @param array $platform_info
	 *        	云云微博搜索平台配置信息 [Must]
	 * @param string $html
	 *        	云云微博搜索结果HTML代码 [Must]
	 * @return array 微博结果数组
	 */
	public function parser_yunyun_html($platform_info, $html) {
		if (empty ( $platform_info ) || ! is_array ( $platform_info ) || empty ( $html )) {
			log_message ( 'error', "parser_yun param is error !! platform_info:{$platform_info} --- html_content:{$html}" );
			return false;
		}
		
		$start_str = "displaySearchResult(_yrE('searchtabContainer'), state,";
		$end_str = 'createHotWeiboKeywordsView';
		$start_str = preg_quote ( $start_str, '/' );
		$end_str = preg_quote ( $end_str, '/' );
		
		preg_match ( '/' . $start_str . '(.*?)' . $end_str . '/ims', $html, $matches );
		
		$feed_list = $matches [1];
		$feed_list = json_decode ( str_replace ( array (
				"\r\n",
				"\r",
				"\n",
				');' 
		), '', $feed_list ), true );
		// print_r($feed_list);exit;
		/*
		 * $feed_list = str_replace(array('[',']'),array('array(',')'),$feed_list);
		 * $feed_list = preg_replace('|{"(.*?)":|','array("$1"=>',$feed_list);
		 * $feed_list = str_replace(array('}','":','\/'),array(')','"=>','/'),$feed_list);
		 *
		 * eval('$str = ' . $feed_list . ';');
		 */
		// print_r($str[0]);exit;
		foreach ( $feed_list [0] as $userinfo ) {
			$info = $userinfo [0];
			
			$current_data = $this->wbfield;
			
			// 转发ID
			$current_data ['retweeted_id'] = '';
			
			// 昵称
			$current_data ['user'] ['name'] = iconv_decode ( $info [0] [1] ); // preg_replace("#\\\u([0-9a-f]{4})#ie", "iconv('UCS-2', 'UTF-8', pack('H4', '\\1'))", $info[0][1]);
			                                                           // 获取微博内容
			$current_data ['text'] = unicode_decode ( $info [0] [2] ); // preg_replace("#\\\u([0-9a-f]{4})#ie", "iconv('UCS-2', 'UTF-8', pack('H4', '\\1'))", $info[0][2]);
			                                                     
			// 是否加V
			if (@$info [0] [9]) {
				$use_verified = 1;
			} else {
				$use_verified = 0;
			}
			$current_data ['user'] ['verified'] = $use_verified;
			
			// 转发
			$current_data ['reposts_count'] = $info [0] [5] ? $info [0] [5] : 0;
			
			// 评论
			$current_data ['comments_count'] = $info [0] [6] ? $info [0] [6] : 0;
			
			// 详情URL
			$current_data ['url'] = $info [0] [0];
			
			// 微博内容中的图片
			$current_data ['thumbnail_pic'] = $info [0] [3] [0] [0];
			$current_data ['bmiddle_pic'] = $info [0] [3] [0] [1];
			$current_data ['original_pic'] = $info [0] [3] [0] [2];
			
			// 来源
			$current_data ['source'] = $info [3];
			$source = $info [3];
			$url_explode = explode ( '/', $current_data ['url'] );
			
			// 文章ID
			if (strpos ( $source, 'weibo.com' )) {
				$wid = $url_explode [count ( $url_explode ) - 1];
				$userid = $url_explode [count ( $url_explode ) - 2];
				// 用户ID
				$current_data ['user'] ['id'] = $userid;
				// 用户空间
				$current_data ['user'] ['profile_url'] = $source . '/' . $userid;
				// 文章ID
				$current_data ['_id'] = $this->sinaWburl2ID ( $wid );
			} elseif (strpos ( $source, 't.163.com' ) || strpos ( $source, 't.qq.com' ) || strpos ( $source, 't.sohu.com' )) {
				// 文章ID
				$current_data ['_id'] = $info [8] [0];
				// 用户空间
				$current_data ['user'] ['profile_url'] = $info [0] [4];
				
				$url_explode = explode ( '/', $current_data ['user'] ['profile_url'] );
				// 用户ID
				$current_data ['user'] ['id'] = $url_explode [count ( $url_explode ) - 1];
			}
			// 发布时间
			$current_data ['ctime'] = ctype_digit ( $info [2] ) ? $info [2] : time ();
			
			// 头像
			// $current_data['user']['profile_image_url'] = $info[1][1];
			$current_data ['user'] ['header_url'] = $info [1] [1];
			// 来源
			$source_url = str_replace ( 'http://', '', $source );
			switch ($source_url) {
				case 'weibo.com' :
					$platform = 'sina';
					break;
				case 't.qq.com' :
					$platform = 'tencent';
					break;
				case 't.163.com' :
					$platform = 'netease';
					break;
				case 't.sohu.com' :
					$platform = 'sohu';
					break;
			}
			
			$current_data ['platform'] = $platform;
			// 增加时间
			$current_data ['addtime'] = time ();
			// 渠道
			$current_data ['source_myid'] = $platform_info ['source_myid'];
			$this->result [] = $current_data;
		}
		return $this->result;
	}
	/**
	 * 解析网易平台HTML搜索结果页面内容，提出标准微博内容数组
	 *
	 * @access public
	 * @param array $platform_info
	 *        	网易微博搜索平台配置信息 [Must]
	 * @param string $html
	 *        	网易微博搜索结果HTML代码 [Must]
	 * @return array 微博结果数组
	 */
	public function parser_netease($platform_info, $data, $tweet = FALSE) {
		$result_array = array ();
		$this->load->helper ( 'MY_common_helper' );
		foreach ( $data as $eval_data ) {
			$current_data = $this->wbfield;
			$id = strval ( $eval_data ['id'] );
			// 文章ID
			$current_data ['_id'] = $id;
			// 内容
			$current_data ['text'] = $eval_data ['content'];
			// 创建时间
			$current_data ['ctime'] = $eval_data ['prettyTime'] ? my_strtotime ( $eval_data ['prettyTime'] ) : time ();
			
			// my_strtotime 函数无法处理时，为当前时间
			if (empty ( $current_data ['ctime'] ))
				$current_data ['ctime'] = time ();
				
				// 转发数
			$current_data ['reposts_count'] = $eval_data ['retweetCount'];
			// 评论数
			$current_data ['comments_count'] = $eval_data ['replyCount'];
			// 好评数
			$current_data ['attitudes_count'] = $eval_data ['topPostCount'];
			// 用户ID
			$current_data ['user'] ['id'] = strval ( $eval_data ['user'] ['id'] );
			// 用户URL
			$current_data ['user'] ['profile_url'] = 'http://t.163.com/' . $eval_data ['user'] ['screenName'];
			// 昵称
			$current_data ['user'] ['name'] = $eval_data ['user'] ['nickName'];
			// 头像
			$current_data ['user'] ['header_url'] = $eval_data ['user'] ['avatar'];
			// 描述 description
			$current_data ['user'] ['description'] = $eval_data ['user'] ['description'];
			// 是否加V
			$current_data ['user'] ['verified'] = $eval_data ['user'] ['sysTag'] ? 1 : 0;
			// 粉丝数
			$current_data ['user'] ['followers_count'] = $eval_data ['user'] ['followerCount'];
			// 关注数
			$current_data ['user'] ['friends_count'] = $eval_data ['user'] ['followingCount'];
			//
			// 详情URL
			$current_data ['url'] = 'http://t.163.com/' . $eval_data ['user'] ['screenName'] . '/status/' . $eval_data ['id'];
			// 微博内容中的图片
			$current_data ['thumbnail_pic'] = isset ( $eval_data ['imageList'] [0] ) ? isset ( $eval_data ['imageList'] [0] ) : '';
			$current_data ['bmiddle_pic'] = '';
			$current_data ['original_pic'] = '';
			// 增加时间
			$current_data ['addtime'] = time ();
			// 来源
			$current_data ['source'] = $eval_data ['source'];
			// 渠道
			$current_data ['source_myid'] = $platform_info ['source_myid'];
			
			if ($tweet === TRUE) {
				return $current_data;
			}
			// 是为否转发
			if (array_key_exists ( 'rootTweetId', $eval_data ) && $eval_data ['rootTweetId'] != 0) {
				$current_data ['retweeted_id'] = strval ( $eval_data ['rootTweetId'] );
				$current_data ['retweeted_uid'] = $eval_data ['relatedTweet'] ['root'] ['user'] ['id'];
				$current_data ['retweeted_name'] = $eval_data ['relatedTweet'] ['root'] ['user'] ['nickName'];
				// $result_array[$id] = $current_data;
				$result_array [] = $current_data;
				if (! isset ( $result_array [$current_data ['retweeted_id']] )) {
					// $result_array[$current_data['retweeted_id']] = $this->parser_netease($platform_info, $eval_data['relatedTweet'], TRUE);
					$result_array [] = $this->parser_netease ( $platform_info, $eval_data ['relatedTweet'], TRUE );
				}
			} else {
				// $result_array[$id] = $current_data;
				$result_array [] = $current_data;
			}
		}
		
		return $result_array;
	}
	
	/**
	 * 解析腾讯平台HTML搜索结果页面内容，提出标准微博内容数组
	 *
	 * @access public
	 * @param array $platform_info
	 *        	腾讯微博搜索平台配置信息 [Must]
	 * @param string $html
	 *        	腾讯微博搜索结果HTML代码 [Must]
	 * @return array 微博结果数组
	 */
	public function parser_tencent($platform_info, $html) {
		$this->load->library ( 'Http_fetch' );
		$weibo = $this->http_fetch;
		$weibo->htmlcontent = $html;
		
		$start_str = '<ul id="talkList" class="LC"';
		$end_str = '<div class="pageNav blueFoot"';
		
		$feed_list = $weibo->get ( $start_str, $end_str );
		if ($feed_list === FALSE) {
			return FALSE;
		}
		$userinfo = $feed_list [0];
		$weibo->htmlcontent = $userinfo;
		
		$aArr = $weibo->getAttr ( 'li', '', true );
		
		foreach ( ( array ) $aArr as $key => $val ) {
			$current_data = $this->wbfield;
			// 文章id
			if (! isset ( $val ['attr'] )) {
				continue;
			}
			$current_data ['_id'] = $val ['attr'] ['id'];
			
			// 时间
			// $current_data['ctime'] = '';
			
			if (! empty ( $val ['attr'] [' rel'] ))
				$current_data ['ctime'] = $val ['attr'] [' rel'];
			if (! empty ( $val ['attr'] ['rel'] ))
				$current_data ['ctime'] = $val ['attr'] ['rel'];
			
			$preg_macth_result = preg_match ( '|class="userPic"><a href="(.*?)".*?titlename="(.*?)\(@.*?".*?<img.*?src="(.*?)".*?</a>|ims', $val ['content'], $matches );
			
			if ($preg_macth_result < 1) {
				preg_match ( '|class="userPic"><a href="(.*?)".*?title="(.*?)\(@.*?".*?<img.*?src="(.*?)".*?</a>|ims', $val ['content'], $matches );
			}
			
			// 昵称
			$current_data ['user'] ['name'] = $matches [2];
			// 头像
			$current_data ['user'] ['header_url'] = $matches [3];
			
			// 用户url
			$current_data ['user'] ['profile_url'] = $matches [1];
			// 用户ID
			list ( , $id ) = explode ( 't.qq.com/', $matches [1] );
			
			$current_data ['user'] ['id'] = $id;
			
			// 是否加V
			if (strstr ( $val ['content'], 'tIcon ico_cvip' )) {
				$use_verified = 1;
			} else {
				$use_verified = 0;
			}
			$current_data ['user'] ['verified'] = $use_verified;
			
			$weibo->htmlcontent = $val ['content'];
			
			// 获取微博内容
			$weibo->htmlcontent = $val ['content'];
			$start_str = '<div class="msgCnt">';
			$end_str = '</div>';
			
			$wcontent = $weibo->get ( $start_str, $end_str );
			
			$current_data ['text'] = strip_tags ( $wcontent [0], '<a>' );
			if (empty ( $current_data ['text'] )) {
				$current_data ['text'] = "转播";
			}
			
			// 发布时间、时间、转播、评论
			
			$weibo->htmlcontent = $val ['content'];
			$start_str = '<div class="pubInfo';
			$end_str = '</div>';
			
			$content = $weibo->get ( $start_str, $end_str );
			if (count ( $content ) > 1) {
				$weibo->htmlcontent = $content [1];
			} else {
				$weibo->htmlcontent = $content [0];
			}
			
			$aArr = $weibo->getAttr ( 'a', '', true );
			
			foreach ( ( array ) $aArr as $key => $relay_comt ) {
				if (isset ( $relay_comt ['attr'] ['class'] ) && $relay_comt ['attr'] ['class'] == 'relay') { // 详情URL
					$current_data ['url'] = $relay_comt ['attr'] ['href'];
					// 转发
					$current_data ['reposts_count'] = $relay_comt ['attr'] ['num'];
				}
				// 评论
				if (isset ( $relay_comt ['attr'] ['class'] ) && $relay_comt ['attr'] ['class'] == 'comt') {
					$current_data ['comments_count'] = $relay_comt ['attr'] ['num'];
				}
				// 来源
				if (isset ( $relay_comt ['attr'] ['class'] ) && $relay_comt ['attr'] ['class'] == 'f') {
					$iArr = $weibo->getAttr ( 'i', '', true );
					$current_data ['source'] = str_replace ( '来自', '', $iArr [0] ['attr'] ['title'] );
				}
			}
			
			/* js 图片,无法获取 */
			// 微博内容中的图片
			$current_data ['thumbnail_pic'] = '';
			$current_data ['bmiddle_pic'] = '';
			$current_data ['original_pic'] = '';
			
			// 增加时间
			$current_data ['addtime'] = time ();
			
			// 渠道
			$current_data ['source_myid'] = $platform_info ['source_myid'];
			
			// 是否转载
			if (false != ($retweeted = $this->forward_tencent ( $platform_info, $val ['content'] ))) {
				$current_data ['retweeted_id'] = $retweeted ['id'];
				$current_data ['retweeted_uid'] = $retweeted ['uid'];
				$current_data ['retweeted_name'] = $retweeted ['name'];
			}
			
			$this->result [] = $current_data;
		}
		
		return array_merge ( $this->result, $this->tweet );
	}
	
	/**
	 * 解析腾讯平台 client客户端 页面接口返回的数据
	 * 返回我们需要的结构数组
	 * 此处若接到的列表中有转发数据..会把转发的微博抽出来,并入列表
	 *
	 * @access public
	 * @param string $source_myid
	 *        	标识抓取渠道的id..此处为6-2 [Must]
	 * @param string $response_string
	 *        	腾讯微博给出的response..此处为json串 [Must]
	 * @return array
	 */
	public function parser_tencent_client($source_myid, $response_string) {
		if (empty ( $source_myid ) || empty ( $response_string )) {
			log_message ( 'error', "parser_tencent_client param is error !! source_myid:{$source_myid}--response_string:{$response_string}" );
			return false;
		}
		
		$response_array = json_decode ( $response_string, true );
		$totalCount = $response_array ['info'] ['totalCount'];
		if ($totalCount < 1)
			return false;
		
		$response_data = $response_array ['jsonDump'] ['msgs'];
		$response_data_count = count ( $response_data );
		if ($response_data_count < 1)
			return false;
		
		foreach ( $response_data as $key => $value ) {
			// var_dump($value['msgId']);exit;
			// var_dump($value);exit;
			$loop = 1;
			for($i = 1; $i <= $loop; $i ++) {
				$final_data [$key] ['_id'] = strval ( $value ['msgId'] );
				$final_data [$key] ['text'] = $value ['content'];
				$final_data [$key] ['ctime'] = my_strtotime ( $value ['postTime'] );
				$final_data [$key] ['source'] = isset ( $value ['source'] ) ? $value ['source'] : '';
				$final_data [$key] ['reposts_count'] = $value ['forwardCount'];
				$final_data [$key] ['comments_count'] = $value ['forwardCount'];
				$final_data [$key] ['attitudes_count'] = 0;
				$final_data [$key] ['url'] = 'http://t.qq.com/p/t/' . strval ( $value ['msgId'] );
				if ($value ['imgSrc']) {
					$final_data [$key] ['thumbnail_pic'] = $value ['imgSrc'] . '/160';
					$final_data [$key] ['bmiddle_pic'] = $value ['imgSrc'] . '/460';
					$final_data [$key] ['original_pic'] = $value ['imgSrc'] . '/2000';
				} else {
					$final_data [$key] ['thumbnail_pic'] = '';
					$final_data [$key] ['bmiddle_pic'] = '';
					$final_data [$key] ['original_pic'] = '';
				}
				
				$final_data [$key] ['addtime'] = time ();
				$final_data [$key] ['source_myid'] = $source_myid;
				$final_data [$key] ['retweeted_id'] = '';
				$final_data [$key] ['retweeted_uid'] = '';
				$final_data [$key] ['retweeted_name'] = '';
				
				// 用户信息
				$final_data [$key] ['user'] ['id'] = $value ['authorId']; // $value['openid'];
				$final_data [$key] ['user'] ['openid'] = '';
				// $final_data[$key]['user']['screen_name'] = $value['nick'];
				$final_data [$key] ['user'] ['name'] = $value ['username'];
				$final_data [$key] ['user'] ['description'] = '';
				$final_data [$key] ['user'] ['profile_url'] = "http://t.qq.com/{$value['authorId']}";
				$final_data [$key] ['user'] ['header_url'] = empty ( $value ['authorImgUrl'] ) ? '' : $value ['authorImgUrl'];
				$final_data [$key] ['user'] ['followers_count'] = '';
				$final_data [$key] ['user'] ['friends_count'] = '';
				
				$final_data [$key] ['user'] ['verified'] = ($value ['msgAuthorIsVIP']) ? 1 : 0; // 0-不是，1-是
				                                                                            
				// 看是不是转播
				if (isset ( $value ['sourceMsg'] ) && ! empty ( $value ['sourceMsg'] )) {
					$final_data [$key] ['retweeted_id'] = $value ['sourceMsg'] ['msgId'];
					$final_data [$key] ['retweeted_uid'] = $value ['sourceMsg'] ['authorId'];
					$final_data [$key] ['retweeted_name'] = $value ['sourceMsg'] ['username'];
					
					$key = $tweet_key;
					$tweet_key ++;
					$value = $value ['sourceMsg'];
					$loop = 2;
				}
			}
		}
		
		return $final_data;
	}
	
	/**
	 * 解析腾讯平台HTML搜索结果转发页面内容，提出标准微博内容数组
	 *
	 * @access public
	 * @param array $platform_info
	 *        	搜狐微博搜索平台配置信息 [Must]
	 * @param string $fHTML
	 *        	搜索结果转发页面内容 [Must]
	 * @return array 微博结果数组
	 */
	public function forward_tencent($platform_info, $fHTML) {
		/**
		 * ****转发*******
		 */
		if (preg_match ( '|<div class="replyBox">.*<div class="funBox|ims', $fHTML, $Rmatches )) {
			$this->deltext = $Rmatches [0];
			
			$current_data = $this->wbfield;
			
			// 用户URL,昵称,用户id
			preg_match ( '|<a href="(.*?)".*?title.*?gender.*?>(.*?)</a>|ims', $Rmatches [0], $matches );
			
			$current_data ['user'] ['name'] = $matches [2];
			
			$current_data ['user'] ['profile_url'] = $matches [1];
			
			list ( , $userid ) = explode ( 't.qq.com/', $matches [1] );
			
			$current_data ['user'] ['id'] = $userid;
			
			// 内容
			preg_match ( '|</strong>(.*?)</div>|ims', $Rmatches [0], $matches );
			
			$current_data ['text'] = $matches [1];
			
			// 图片
			if (preg_match ( '|<div class="picBox.*?href="(.*?)".*?crs="(.*?)"|ims', $Rmatches [0], $matches )) {
				$current_data ['thumbnail_pic'] = $matches [2];
				$current_data ['bmiddle_pic'] = $matches [1];
				$current_data ['original_pic'] = '';
			}
			
			// URL,ID,时间
			
			preg_match ( '|<a class="time".*?href="(.*?)".*?rel="(.*?)"|ims', $Rmatches [0], $matches );
			
			$current_data ['ctime'] = $matches [2];
			
			$current_data ['url'] = $matches [1];
			
			list ( , $id ) = explode ( '/p/t/', $matches [1] );
			
			$current_data ['_id'] = $id;
			
			// 转发，评论
			preg_match ( '|<b class="relayNum">(\d+)</b>|ims', $Rmatches [0], $matches );
			
			$current_data ['reposts_count'] = $matches [1];
			
			$current_data ['comments_count'] = $matches [1];
			
			// 是否加V
			if (strstr ( $Rmatches [0], 'tIcon ico_cvip' )) {
				$use_verified = 1;
			} else {
				$use_verified = 0;
			}
			$current_data ['user'] ['verified'] = $use_verified;
			
			// 头像
			$current_data ['user'] ['header_url'] = '';
			
			// 转载的ID
			$current_data ['retweeted_id'] = '';
			
			// 增加时间
			$current_data ['addtime'] = time ();
			// 来源
			preg_match ( '|<a class="f" .*?>(.*?)</a>|ims', $Rmatches [0], $matches );
			$source = str_replace ( '来自', '', $matches [1] );
			$current_data ['source'] = $source;
			
			// 渠道
			$current_data ['source_myid'] = $platform_info ['source_myid'];
			
			$this->tweet [$current_data ['_id']] = $current_data;
			
			return array (
					'id' => $current_data ['_id'],
					'uid' => $current_data ['user'] ['id'],
					'name' => $current_data ['user'] ['name'] 
			);
		} else {
			
			return;
		}
	/**
	 * ****转发结束*******
	 */
	}
	
	/**
	 * 解析搜狐平台HTML搜索结果页面内容，提出标准微博内容数组
	 *
	 * @access public
	 * @param array $platform_info
	 *        	搜狐微博搜索平台配置信息 [Must]
	 * @param string $html
	 *        	搜狐微博搜索结果HTML代码 [Must]
	 * @return array 微博结果数组
	 */
	public function parser_sohu($platform_info, $html) {
		if (empty ( $platform_info ) || ! is_array ( $platform_info ) || empty ( $html )) {
			log_message ( 'error', "parser_sohu param is error !! platform_info:{$platform_info} --- html_content:{$html}" );
			return false;
		}
		$html = mb_convert_encoding ( $html, 'UTF-8', 'GBK' );
		
		// 加V ，class="twi twiHasPic "
		// 转载， <div id="6785041864_6781222710_con" class="twiRoot"> ，6785041864 转载ID，6781222710 被转载ID
		if (preg_match_all ( '/\<div id=\"\d+?[^_]\d+?_con\" class=\"twi.*?\".*?\>/ims', $html, $matches )) {
			$offset = 0;
			foreach ( ( array ) $matches [0] as $info ) {
				$offset = strpos ( $html, $info, $offset );
				$offsetList [] = $offset;
				$offset ++;
			}
			
			$count = count ( $offsetList ) - 1;
			for($i = 0; $i < $count; $i ++) {
				$len = $offsetList [$i + 1] - $offsetList [$i];
				$conList [] = substr ( $html, $offsetList [$i], $len );
			}
			
			foreach ( ( array ) $conList as $conEle ) {
				$current_data = $this->wbfield;
				
				$retweet = 0;
				
				preg_match ( '/\<div id=\"(\d+?)_con\" class=\"twi.*?\".*?\>/ims', $conEle, $strid );
				
				// 微博ID
				$current_data ['_id'] = $strid [1];
				// 转载的微博ID
				$current_data ['retweeted_id'] = '';
				
				/**
				 * ****转发*******
				 */
				$end_str = '<div class="twiB">';
				$preg_str = preg_quote ( $end_str, '/' );
				
				if (preg_match ( '/\<div id=\"(\d+?)_(\d+?)_con\" class=\"twi.*' . $preg_str . '/ims', $conEle, $rt_matches )) {
					$rt_content = $rt_matches [0];
					$rt_id = $rt_matches [2];
					
					$current_data ['_id'] = $rt_matches [2];
					$current_data ['retweeted_id'] = '';
					
					$len = strrpos ( $rt_content, $end_str );
					$rt_content = substr ( $rt_content, 0, $len );
					
					$retweeted = $this->parser_sohu_secondary ( $platform_info, $rt_content, $current_data, 1 );
					
					$current_data ['_id'] = $rt_matches [1];
					$current_data ['retweeted_id'] = $retweeted ['id'];
					$current_data ['retweeted_uid'] = $retweeted ['uid'];
					$current_data ['retweeted_name'] = $retweeted ['name'];
					
					$conEle = str_replace ( $rt_content, '', $conEle );
				}
				
				/**
				 * ****转发结束*******
				 */
				
				$this->parser_sohu_secondary ( $platform_info, $conEle, $current_data, 0 );
			}
		} else {
			log_message ( 'error', "Data of parser_tencent is null from Htmlsearchparser_model,matches is error!!" );
			return false;
		}
		
		return array_merge ( $this->result, $this->tweet );
	}
	
	/**
	 * 解析xx平台HTML搜索结果页面内容，提出标准微博内容数组
	 *
	 * @access public
	 * @param array $platform_info
	 *        	xx微博搜索平台配置信息 [Must]
	 * @param string $html
	 *        	xx微博搜索结果HTML代码 [Must]
	 * @return array 微博结果数组
	 */
	public function parser_xxx($platinfo, $html) {
		if (empty ( $platform_info ) || ! is_array ( $platform_info ) || empty ( $html )) {
			log_message ( 'error', "parser_yun param is error !! platform_info:{$platform_info} --- html_content:{$html}" );
			return false;
		}
		
		// 最张结构化数据结构...后边相关 其它字段自行调整
		$arrdata = array (
				'id' => '微博 id',
				'uid' => '发布作者ID',
				'text' => '微博内容',
				'ctime' => '微博内容发布时间',
				'addtime' => '抓取到时间',
				'source_myid' => $platform_info ['source_myid'],
				'platform' => '是那个平台的数据.如新浪:sina/腾讯:tencent/网易:netease/搜狐:sohu  等...' 
		);
		
		return $arrdata;
	}
	
	/**
	 * 解析新浪平台HTML搜索结果转发页面内容，提出标准微博内容数组
	 *
	 * @access public
	 * @param array $platform_info
	 *        	搜狐微博搜索平台配置信息 [Must]
	 * @param string $Rmatches[0]
	 *        	搜索结果转发页面内容 [Must]
	 * @return array 微博结果数组
	 */
	public function forward_sina_html($platform_info, $fHTML) {
		/**
		 * ****转发*******
		 */
		return false;
		// $start_str = preg_quote('<div class=\"comment_info\" >','/');
		$start_str = '<div class=\"comment\">';
		
		// $end_str = preg_quote('<\/div>\s*<\/div>\s*<\/div>\s*<\/div>','/');
		$end_str = '<\/div>\s*<\/div>\s*<\/div>\s*<\/div>';
		
		if (preg_match ( '/' . $start_str . '.*?' . $end_str . '/ims', $fHTML, $rt_matches )) {
			$current_data = $this->wbfield;
			$this->deltext = $rt_matches [0];
			
			$rt = $rt_matches [0];
			
			// if(preg_match('|<a nick-name="(.*?)".*?href="(.*?)".*?<em>(.*?)</em>.*?\\\u8f6c\\\u53d1\((.*?)\).*?<a href="(.*?)".*?\\\u8bc4\\\u8bba\(?(\d+)?\)?.*?date="(.*?)"|is',$rt,$match))
			if (preg_match ( '|<a class="W_texta W_fb" nick-name="(.*?)"\s*href="(.*?)"\s*.*?title.*?\s*<\/a>\s*<p class="comment_txt">(.*?)<\/p>.*?\\\u8f6c\\\u53d1<em>(.*?)<\/em>.*?\\\u8bc4\\\u8bba\s*<em>.*?\s*(.*?)\s*<\/em>.*?<a href="(.*?)"\s*date="(\d*)|ims', $rt, $match )) 

			{
				// var_dump($match);die;
				// 昵称
				$current_data ['user'] ['name'] = iconv_decode ( $match [1] );
				// 用户URL
				$current_data ['user'] ['profile_url'] = $match [2];
				// 内容
				$current_data ['text'] = iconv_decode ( $match [3] );
				$current_data ['text'] = strip_tags ( $current_data ['text'], "<a><img>" );
				// 转发
				$current_data ['reposts_count'] = $match [4];
				// 详情URL
				$current_data ['url'] = $match [5];
				
				// 用户ID
				$list = explode ( '/', $match [6] );
				$pos = count ( $list ) - 2;
				$current_data ['user'] ['id'] = $list [$pos];
				
				// 微博ID
				$current_data ['_id'] = $this->sinaWburl2ID ( $list [$pos + 1] ); // 获取不到ID情况下，例如：1266321801/ymbsPjH6I
				                                                           
				// 评论
				$current_data ['comments_count'] = $match [5];
				// 时间
				$time = substr ( $match [7], 0, 10 );
				$current_data ['ctime'] = $time;
				
				if (strstr ( $rt, 'class="approve' )) {
					$use_verified = 1;
				} else {
					$use_verified = 0;
				}
				$current_data ['user'] ['verified'] = $use_verified;
				
				// 图片
				$current_data ['thumbnail_pic'] = $current_data ['bmiddle_pic'] = $current_data ['original_pic'] = '';
				preg_match ( '|<img class="bigcursor.*?src="(.*?)".*?&mid=(.*?)"|ims', $fHTML, $Imatches );
				
				if ($Imatches) {
					$current_data ['thumbnail_pic'] = $Imatches [1];
					$current_data ['bmiddle_pic'] = str_replace ( 'thumbnail', 'bmiddle', $Imatches [1] );
					$current_data ['original_pic'] = str_replace ( 'thumbnail', 'large', $Imatches [1] );
					
					// 微博ID
					$current_data ['_id'] = $Imatches [2];
				}
				// 来源
				if (preg_match ( '|<a.*? rel="nofollow">(.*?)</a>|ims', $fHTML, $SCmatches )) {
					$current_data ['source'] = iconv_decode ( $SCmatches [1] );
				}
				// 增加时间
				$current_data ['addtime'] = time ();
				// 渠道
				$current_data ['source_myid'] = $platform_info ['source_myid'];
				
				$this->tweet [$current_data ['_id']] = $current_data;
				
				return array (
						'retweeted_id' => $current_data ['_id'],
						'retweeted_uid' => $current_data ['user'] ['id'],
						'retweeted_name' => $current_data ['user'] ['name'] 
				);
			} else {
				
				$this->error = 'match is error from sina!';
			}
			
			return array (
					'retweeted_id' => $current_data ['_id'],
					'retweeted_uid' => $current_data ['user'] ['id'],
					'retweeted_name' => $current_data ['user'] ['name'] 
			);
			;
		} else {
			
			return false;
		}
	
	/**
	 * ****转发结束*******
	 */
	}
	
	/**
	 * 解析新浪平台WAP搜索结果转发页面内容，提出标准微博内容数组
	 *
	 * @access public
	 * @param array $platform_info
	 *        	搜狐微博搜索平台配置信息 [Must]
	 * @param string $fHTML
	 *        	搜索结果转发页面内容 [Must]
	 * @return array 微博结果数组
	 */
	public function forward_sina($platform_info, $fHTML) {
		/**
		 * ****转发*******
		 */
		$start_str = '<span class="cmt">';
		$end_str = '转发理由:</span>';
		
		if (preg_match ( '|' . $start_str . '(.*?)' . $end_str . '|ims', $fHTML, $matches )) {
			$current_data = $this->wbfield;
			$this->deltext = $matches [0];
			$userinfo = $matches [1];
			// 头像、昵称
			if (preg_match ( '|<a href="http://weibo.cn/u/(\d*).*?">(.*?)</a>|ims', $userinfo, $matches )) {
				$current_data ['user'] ['id'] = $matches [1];
				$current_data ['user'] ['profile_url'] = "http://weibo.cn/u/" . $matches [1];
				$current_data ['user'] ['name'] = $matches [2];
			}
			// 内容
			if (preg_match ( '|<span class="ctt">(.*?)<span class="cmt">|ims', $userinfo, $matches )) {
				$current_data ['text'] = strip_tags ( $matches [0], '<a>' );
			}
			
			$current_data ['text'] = preg_replace ( '|<a href.*?</a>|ims', '', $current_data ['text'] );
			
			// $current_data['text'] = preg_replace('|<a.*href=".*?">.*?</a>|ims','',$current_data['text']);
			
			// 图片
			if (preg_match ( '|<img src="(.*?)"|ims', $userinfo, $matches )) {
				$current_data ['thumbnail_pic'] = $matches [1];
				$current_data ['bmiddle_pic'] = str_replace ( 'wap128', 'bmiddle', $matches [1] );
				$current_data ['original_pic'] = str_replace ( 'wap128', 'woriginal', $matches [1] );
			}
			
			// 微博URL, 微博ID ( 1266321801/ymbsPjH6I )
			if (preg_match ( '|<a href="http://weibo.cn/comment/(.*?)\?.*?"|ims', $userinfo, $matches )) {
				$current_data ['_id'] = $this->sinaWburl2ID ( $matches [1] );
				$current_data ['mid'] = $matches [1];
				if ($current_data ['user'] ['id']) {
					$current_data ['url'] = 'http://weibo.cn/' . $current_data ['user'] ['id'] . '/' . $matches [1];
				}
			}
			// 是否加V
			if (preg_match ( '|<img src=".*?" alt="V">|ims', $userinfo, $Vmatches )) {
				$use_verified = 1;
			} else {
				$use_verified = 0;
			}
			$current_data ['user'] ['verified'] = $use_verified;
			
			// 渠道
			$current_data ['source_myid'] = $platform_info ['source_myid'];
			
			// 转发
			if (preg_match ( '|原文转发\[(\d*)\]|ims', $userinfo, $matches )) {
				$current_data ['reposts_count'] = $matches [1];
			}
			// 评论
			if (preg_match ( '|原文评论\[(\d*)\]|ims', $userinfo, $matches )) {
				$current_data ['comments_count'] = $matches [1];
			}
			// 表态数(好评数)
			if (preg_match ( '|赞\[(\d*)\]|ims', $userinfo, $matches )) {
				$current_data ['attitudes_count'] = $matches [1];
			}
			
			// 创建时间，(因无法获取,创建时间为当前时间)
			$current_data ['ctime'] = time ();
			// 增加时间
			$current_data ['addtime'] = time ();
			// 被转发的微博无法获得微博ID或用户ID时，不入库。
			if (empty ( $current_data ['_id'] ) || empty ( $current_data ['user'] ['id'] )) {
				return false;
			}
			$this->tweet [] = $current_data;
			
			return array (
					'id' => $current_data ['_id'],
					'uid' => $current_data ['user'] ['id'],
					'name' => $current_data ['user'] ['name'] 
			);
		} else {
			return false;
		}
	
	/**
	 * ****转发结束*******
	 */
	}
	
	/**
	 * 二次解析搜狐平台HTML搜索结果转发页面内容，提出标准微博内容数组
	 *
	 * @access public
	 * @param array $platform_info
	 *        	搜狐微博搜索平台配置信息 [Must]
	 * @param string $conEle
	 *        	搜索结果转发页面内容 [Must]
	 * @param array $current_data
	 *        	搜索结果转发页面内容 [Must]
	 * @return array 微博结果数组
	 */
	public function parser_sohu_secondary($platform_info, $conEle, &$current_data, $retweet) {
		$this->load->library ( 'Http_fetch' );
		$weibo = $this->http_fetch;
		
		// 获取用户是否加V
		if (strpos ( $conEle, 'twi twiHasPic' )) {
			$use_verified = 1;
		} else {
			$use_verified = 0;
		}
		$current_data ['user'] ['verified'] = $use_verified;
		
		// 用户URL，ID
		preg_match ( '|<a title=.*?data-content=.*?href="http://t.sohu.com/u/(.*?)">(.*?)</a>|ims', $conEle, $match_user );
		
		if ($match_user) {
			// 用户ID
			$current_data ['user'] ['id'] = $match_user [1];
			
			// 用户URL
			$current_data ['user'] ['profile_url'] = 'http://t.sohu.com/u/' . $match_user [1];
			
			// 获取用户名称
			$current_data ['user'] ['name'] = $match_user [2];
		}
		
		$weibo->htmlcontent = $conEle;
		
		$pAttr = $weibo->getAttr ( 'p', '', true );
		
		foreach ( ( array ) $pAttr as $pEle ) {
			
			if (trim ( $pEle ['attr'] ['class'] ) == 'avt') {
				// 用户ID
				$current_data ['user'] ['id'] = $pEle ['attr'] ['ref'];
				
				// 用户URL
				$current_data ['user'] ['profile_url'] = 'http://t.sohu.com/u/' . $pEle ['attr'] ['ref'];
				
				preg_match ( '|<i title="(.*?)".*? style="background-image: url\((.*?)\)" class="img">|ims', $pEle ['content'], $uimg );
				
				// 获取用户名称
				$current_data ['user'] ['name'] = $uimg [1];
				
				// 获取图片地址
				$current_data ['user'] ['header_url'] = $uimg [2];
			}
			
			if (in_array ( $pEle ['attr'] ['class'], array (
					'ugc ugc2',
					'ugc' 
			) )) {
				// 获取微博内容
				// $html = iconv('GBK','UTF-8',$html);
				// $html =mb_convert_encoding($html,'UTF-8','GBK');
				$current_data ['text'] = $pEle ['content'];
			}
		}
		
		// 微博内容中的图片
		$imgAttr = $weibo->getAttr ( 'img' );
		if (is_array ( $imgAttr )) {
			foreach ( ( array ) $imgAttr as $imgEle ) {
				if (@$imgEle ['attr'] ['lazysrc']) {
					list ( $img, ) = explode ( 'src=', $imgEle ['attr'] ['lazysrc'], 2 );
					$current_data ['thumbnail_pic'] = $img;
					$current_data ['bmiddle_pic'] = str_replace ( '/f_', '/m_', $img );
					$current_data ['original_pic'] = str_replace ( '/f_', '/', $img );
				}
			}
		}
		
		$weibo->htmlcontent = $conEle;
		// 获取微博的发布时间
		$start_str = '<div class="twiB">';
		$end_str = '</div>';
		$twiB = $weibo->get ( $start_str, $end_str );
		
		$weibo->htmlcontent = $twiB [0];
		
		// 微博URL
		$aAttr = $weibo->getAttr ( 'a' );
		$current_data ['url'] = $aAttr [0] ['attr'] ['href'];
		
		// 微博时间
		$bAttr = $weibo->getAttr ( 'b' );
		
		foreach ( ( array ) $bAttr as $bEle ) {
			if (@$bEle ['attr'] ['class'] == 'tm') {
				$current_data ['ctime'] = strtotime ( $bEle ['attr'] ['title'] . ":00" );
			}
		}
		
		$qAttr = $weibo->getAttr ( 'q', '', true );
		
		// 转发
		$current_data ['reposts_count'] = $qAttr [0] ['content'] ? str_replace ( array (
				')',
				'(' 
		), '', $qAttr [0] ['content'] ) : 0;
		// 评论
		$current_data ['comments_count'] = $qAttr [1] ['content'] ? str_replace ( array (
				')',
				'(' 
		), '', $qAttr [1] ['content'] ) : 0;
		// 来源
		preg_match ( '|<b class="from".*?<i.*?>(.*?)</i></b>|ims', $conEle, $from_match );
		$current_data ['source'] = strip_tags ( $from_match [1] );
		// 渠道
		$current_data ['source_myid'] = $platform_info ['source_myid'];
		
		// 增加时间
		$current_data ['addtime'] = time ();
		
		if ($retweet) {
			$this->tweet [] = $current_data;
			return array (
					'id' => $current_data ['_id'],
					'uid' => $current_data ['user'] ['id'],
					'name' => $current_data ['user'] ['name'] 
			);
		} else
			$this->result [] = $current_data;
		
		return true;
	}
	
	/**
	 * function parser sinaweibo search html rules
	 *
	 * 解析新浪微博HTML搜索结果页面内容，提出标准微博内容数组
	 *
	 * @access public
	 * @param
	 *        	array 新浪微博搜索平台配置信息
	 * @param
	 *        	string 新浪微博搜索结果HTML代码
	 * @return array 微博结果数组
	 */
	function pparser_sina($platinfo, $html) {
		
		// 使用正则表达式，解析新浪微博页面内容，返回数组
		$arrdata = array (
				'weibo_id' => '新浪 微博 id',
				'user_id' => '发布作者ID',
				'content' => '微博内容' 
		)
		;
		
		return $arrdata;
	}
	
	/**
	 * function parser sinaweibo search html rules
	 *
	 * 解析新浪微博HTML搜索结果页面内容，提出标准微博内容数组
	 *
	 * @access public
	 * @param
	 *        	array 新浪微博搜索平台配置信息
	 * @param
	 *        	string 新浪微博搜索结果HTML代码
	 * @return array 微博结果数组
	 */
	function pparser_sohu($platinfo, $html) {
		
		// 使用正则表达式，解析新浪微博页面内容，返回数组
		$arrdata = array (
				'weibo_id' => '新浪 微博 id',
				'user_id' => '发布作者ID',
				'content' => '微博内容' 
		)
		;
		
		return $arrdata;
	}
	
	/**
	 * SINA WID TO ID
	 * 
	 * @param
	 *        	$url
	 * @return string
	 */
	function sinaWburl2ID($url) {
		$surl [2] = $this->str62to10 ( substr ( $url, strlen ( $url ) - 4, 4 ) );
		$surl [1] = $this->str62to10 ( substr ( $url, strlen ( $url ) - 8, 4 ) );
		$surl [0] = $this->str62to10 ( substr ( $url, 0, strlen ( $url ) - 8 ) );
		$int10 = $surl [0] . $surl [1] . $surl [2];
		return ltrim ( $int10, '0' );
	}
	function str62to10($str62) { // 62进制到10进制
		$strarry = str_split ( $str62 );
		$str = 0;
		for($i = 0; $i < strlen ( $str62 ); $i ++) {
			$vi = Pow ( 62, (strlen ( $str62 ) - $i - 1) );
			
			$str += $vi * $this->str62keys ( $strarry [$i] );
		}
		$str = str_pad ( $str, 7, "0", STR_PAD_LEFT );
		return $str;
	}
	function str62keys($ks) // 62进制字典
{
		$str62keys = array (
				"0",
				"1",
				"2",
				"3",
				"4",
				"5",
				"6",
				"7",
				"8",
				"9",
				"a",
				"b",
				"c",
				"d",
				"e",
				"f",
				"g",
				"h",
				"i",
				"j",
				"k",
				"l",
				"m",
				"n",
				"o",
				"p",
				"q",
				"r",
				"s",
				"t",
				"u",
				"v",
				"w",
				"x",
				"y",
				"z",
				"A",
				"B",
				"C",
				"D",
				"E",
				"F",
				"G",
				"H",
				"I",
				"J",
				"K",
				"L",
				"M",
				"N",
				"O",
				"P",
				"Q",
				"R",
				"S",
				"T",
				"U",
				"V",
				"W",
				"X",
				"Y",
				"Z" 
		);
		return array_search ( $ks, $str62keys );
	}
	
	
	
	
	public function parser_twitter_html($platform_info, $html) {
				
		if (empty ( $platform_info ) || ! is_array ( $platform_info ) || empty ( $html )) {
			log_message ( 'error', "parser_sina param is error !! platform_info:{$platform_info} --- html_content:{$html}", FALSE, 'keyword/sina' );
			return false;
		}		
		$content = $html;		
		
		$content=$this->PreHand($content);
				
		/* $pattern='/<li class="js-stream-item stream-item stream-item expanding-stream-item" data-item-id="(?P<mid>.*?)"(?:.*?)data-permalink-path="(?P<url>.*?)"(?:.*?)data-screen-name="(?P<name>.*?)"(?:.*?)data-name="(?P<name1>.*?)"(?:.*?)data-user-id="(?P<id>.*?)"(?:.*?)<img class="avatar js-action-profile-avatar" src="(?P<header_url>.*?)"(?:.*?)data-time="(?P<ctime>.*?)"(?:.*?)<p class="TweetTextSize(?:.*?)>(?P<content>.*?)<\/p>(?:.*?)<li class="copy-link-to-tweet js-actionCopyLinkToTweet">/'; */
		$pattern='|<table class="tweet .*?>(?:.*?)<img alt=.*?src="(?P<header_url>.*?)"(?:.*?)<strong class="fullname">(?P<name>.*?)<\/strong>(?:.*?)<span>@<\/span>(?P<name1>.*?)<\/div>(?:.*?)<td class="timestamp">(?:.*?)<a .*?>(?P<ctime>.*?)<\/a>(?:.*?)data-id="(?P<mid>.*?)">(?:.*?)<div class="dir-ltr" dir="ltr">(?P<content>.*?)<\/div>(?:.*?)<span class="metadata">(?:.*?)<a href="(?P<url>.*?)">(?:.*?)<\/table>|';
		$domain='https://www.twitter.com';
		
		
		if (preg_match_all($pattern,$content,$match)) 
		{
			$result=array();
			$count= count($match[0]);			
			for($i=0;$i<$count;$i++)
			{
				$temp=array();
				$temp['_id']=$match['mid'][$i];
				$temp['text']=$match['content'][$i];
				
				$contentpartten='/<img class="twitter-emoji"(.*?)title="(.*?)"(.*?)>/';
				
				$temp['text']=preg_replace($contentpartten,'[${2}]',$temp['text']);
			
				$urlpartten='/<a href="\/hashtag(.*?)>/' ;
				
				$temp['text']=preg_replace($urlpartten,'<a href="'.$domain.'/hashtag${1}>',$temp['text']);
				
			    $atPartten='/<a href="\/(.*?)"([^>]*?)><s>@<\/s><b>(.*?)<\/b>/';
				
			 	$temp['text']=preg_replace($atPartten,'<a href="'.$domain.'/${1}"><s>@</s><b>${1}</b>',$temp['text']);
				
				// 将相对路径转化为绝对路径
				
				$temp['url']=$domain.$match['url'][$i];
				$temp['ctime']=$match['ctime'][$i];
				$imgpattern='#data-img-src="(?P<imgurl>.*?)"#';
				preg_match_all($imgpattern,$match[0][$i],$imgList);
				$imgcount=count($imgList[0]);
				$imglist='';	
				if($imgcount>0)
				{
					//var_dump($imgList);
					for($j=0;$j<$imgcount;$j++)
					{
						$imglist=$imglist.$imgList[1][$j].'*';
					}
				}
				$temp['thumbnail_pic']=$imglist;
				
				$user=array();
				$user['name']=$match['name1'][$i];
				$user['header_url']=$match['header_url'][$i];
				$user['profile_url']=$domain.'/'.$match['name'][$i];
				$user['id']=$match['id'][$i];
				$temp['user']=$user;
				
				$temp['addtime']=time();
				
				
				$atti='/<span class="ProfileTweet-actionCountForAria" >(.*?)<\/span>/';
				if(preg_match_all($atti,$match[0][$i],$attiMatch))
				{		
					$number='/\d+/';
					$temp['reposts_count']=$attiMatch[1][0];
					preg_match($number,$temp['reposts_count'],$num);
					$temp['reposts_count']=$num[0];				
					$temp['attitudes_count']=$attiMatch[1][1] ;
					preg_match($number,$temp['attitudes_count'],$num);
					$temp['attitudes_count']=$num[0];
				}
				
				$atti='/<span class="u-hiddenVisually">(.*?)<\/span>/';
				if(preg_match_all($atti,$match[0][$i],$attiMatch))
				{
					$number='/\d+/';
					$temp['comments_count']=$attiMatch[1][0] ;
					preg_match($number,$temp['comments_count'],$num);
					$temp['comments_count']=$num[0];
				}
						
				$result[]=$temp;
			}
			
			if(empty($result))
			{
				$result[]='error';
			}
			
			return $result;
		
		} else {
			log_message ( 'error', "Data of parser_sina is null from Htmlsearchparser_model,matches is error!!", FALSE, 'keyword/sina' );
			return false;
		}
		
		//return $this->result;
	}
	
	private function PreHand($str)
	{
		$str = str_replace("\r\n","",$str);
		$str = str_replace("\r","",$str);
		$str = str_replace("\n","",$str);
		$str = str_replace("\\r\\n","",$str);
		$str = str_replace("\\r","",$str) ;
		$str = str_replace("\\n","",$str);
		$str = str_replace("\\t","",$str);
		//$str=stripslashes($str);
		return trim($str);
	}
}

?>
